idea配置ssm框架(详细信息,全部流程)

作者:神秘网友 发布时间:2020-09-20 19:16:28

idea配置ssm框架(详细信息,全部流程)

idea配置ssm框架(详细信息,全部流程)

项目ssm配置的信息
1.先创建maven项目
idea配置ssm框架(详细信息,全部流程)

2.选择需要配置的信息,然后点击确定
idea配置ssm框架(详细信息,全部流程)

3.创建项目名称
idea配置ssm框架(详细信息,全部流程)

4.更改下载jar包的位置,从网上下载慢,可以选择本地仓库
idea配置ssm框架(详细信息,全部流程)

更改为本地仓库,这里需要注意,是你maven——apache-maven-3.5.4——conf——settings.xml
我的位置是E:\Maven\apache-maven-3.5.4\conf
idea配置ssm框架(详细信息,全部流程)

勾选完之后,就变成你选的位置,然后点击Finish确定,maven项目就创建好了
idea配置ssm框架(详细信息,全部流程)

创建完之后如下图所示
idea配置ssm框架(详细信息,全部流程)

如果你的里面没有src包可能是正在加载中,要是从远程仓库下载的话,可能需要很长时间

5.下面开始配置jar包,应用依赖
idea配置ssm框架(详细信息,全部流程)

5.1 Spring webmvc

<!-- 引入spring mvc的jar包 -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.3.7.RELEASE</version>
</dependency>

5.2 Spring jdbc

<!--  JDBC支持包,包括数据源设置和JDBC访问支持 -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>4.3.7.RELEASE</version>
</dependency>

5.3 Spring Aspects

<!-- Spring提供对AspectJ框架的整合  -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aspects</artifactId>
  <version>4.3.7.RELEASE</version>
</dependency>

5.4 mybatis

<!-- mybatis依赖包 -->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis</artifactId>
  <version>3.4.2</version>
</dependency>

5.5 MyBatis 引用Spring的适配包

<!-- mybatis引入spring适配包 -->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis-spring</artifactId>
  <version>1.3.1</version>
</dependency>

5.6 数据库连接池 c3p0

<!-- 数据库连接池 c3p0 -->
<!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
<dependency>
  <groupId>c3p0</groupId>
  <artifactId>c3p0</artifactId>
  <version>0.9.1.2</version>
</dependency>

5.7 mysql驱动

<!-- mysql驱动  -->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.13</version>
</dependency>

5.8 引入 jstl

<!-- jstl标签相关的包 -->
<!-- https://mvnrepository.com/artifact/jstl/jstl -->
<dependency>
  <groupId>jstl</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

5.9 引入 servlet-api

<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
</dependency>

5.10 引入 junit

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>

5.11. json
idea配置ssm框架(详细信息,全部流程)

<jackson.version>2.5.4</jackson.version>

加载json包的时候包的时候,需要在上面卸载jar包的版本如图:

<!-- controller返回json -->
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>${jackson.version}</version>
</dependency>

<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>${jackson.version}</version>
</dependency>

12.分页jar包

<!--分页依赖的jar包-->
<dependency>
  <groupId>com.github.pagehelper</groupId>
  <artifactId>pagehelper</artifactId>
  <version>5.0.0</version>
</dependency>

13.通用mapper依赖

<!-- 通用mapper依赖包 -->
<dependency>
  <groupId>tk.mybatis</groupId>
  <artifactId>mapper-spring-boot-starter</artifactId>
  <version>2.1.5</version>
</dependency>

14.需要的可以在加上图片验证码依赖jar包

<!--jar包-->
<dependency>
  <groupId>com.github.whvcse</groupId>
  <artifactId>easy-captcha</artifactId>
  <version>1.6.2</version>
</dependency>

以下为整体的依赖代码

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>news</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>news Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <jackson.version>2.5.4</jackson.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <!-- controller返回json -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson.version}</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>

    <!-- 引入spring mvc的jar包 -->
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.3.7.RELEASE</version>
    </dependency>

    <!--  JDBC支持包,包括数据源设置和JDBC访问支持 -->
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>4.3.7.RELEASE</version>
    </dependency>

    <!-- Spring提供对AspectJ框架的整合  -->
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>4.3.7.RELEASE</version>
    </dependency>

    <!-- mybatis依赖包 -->
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.2</version>
    </dependency>

    <!-- mybatis引入spring适配包 -->
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.1</version>
    </dependency>

    <!-- 数据库连接池 c3p0 -->
    <!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
    <dependency>
      <groupId>c3p0</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.1.2</version>
    </dependency>

    <!-- mysql驱动  -->
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.13</version>
    </dependency>

    <!-- jstl标签相关的包 -->
    <!-- https://mvnrepository.com/artifact/jstl/jstl -->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>

    <!--分页依赖的jar包-->
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.0.0</version>
    </dependency>

    <!-- 通用mapper依赖包 -->
    <dependency>
      <groupId>tk.mybatis</groupId>
      <artifactId>mapper-spring-boot-starter</artifactId>
      <version>2.1.5</version>
    </dependency>

    <!--jar包-->
    <dependency>
      <groupId>com.github.whvcse</groupId>
      <artifactId>easy-captcha</artifactId>
      <version>1.6.2</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>news</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

jar包引完了,这时候需要注意,你需要刷新页面,他才可以加载jar包,点击右上角这个M,idea会自动帮我们加载页面。
idea配置ssm框架(详细信息,全部流程)

如果没有上图M标志,可点击下图,进行刷新
idea配置ssm框架(详细信息,全部流程)

刷新完以后看目录,查看jar,依赖是否下载下来
idea配置ssm框架(详细信息,全部流程)

6.下面开始配置Web.xml文件,他在下图位置
idea配置ssm框架(详细信息,全部流程)

在下面Web.xml中主要配置以下文件
1.启动spring容器,加载spring配置文件applicationContext.xml

<!-- 1.启动spring容器,加载spring配置文件applicationContext.xml -->
<!-- needed for ContextLoaderListener -->
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
</context-param>

<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

点击main,然后点击右键
先添加相应的文件
idea配置ssm框架(详细信息,全部流程)idea配置ssm框架(详细信息,全部流程)

选择相对应的
java选Sources Root
resources选择 Resources Root
idea配置ssm框架(详细信息,全部流程)

如果没有Spring这个配置文件,查看你下载的Spring jar包
下面是创建好的文件,在返回到Web.xml文件中
idea配置ssm框架(详细信息,全部流程)

2.配置Spring mvc的前端控制器,DispatcherServlet类,拦截所有请求,交给Controller处理
idea配置ssm框架(详细信息,全部流程)

<!-- 2.  配置spring mvc 的前端控制器,DispatcherServlet类拦截所有请求,交给controller处理
加载spring mvc配置文件(dispatcherServlet-servlrt.xml,还没有建) -->
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
  <servlet-name>dispatcherServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <!--  不写,写的话需要建个springmvc.xml就不需要dispatcherServlet-servlet.xml -->
  <!--    <init-param>-->
  <!--      <param-name>contextConfigLocation</param-name>-->
  <!--      <param-value>classpath:springmvc.xml</param-value>-->
  <!--    </init-param>-->
  <load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
  <servlet-name>dispatcherServlet</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

然后在创建dispatcherServlet-servlet.xml文件
idea配置ssm框架(详细信息,全部流程)

如下图,要注意创建的路径问题,他和web.xml属于同级
idea配置ssm框架(详细信息,全部流程)

3.加上编码过滤器,为了防止出现乱码

<!-- 编码过滤器,防止出现乱码 -->
<filter>
  <filter-name>characterEncodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
  </init-param>
</filter>

<filter-mapping>
  <filter-name>characterEncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

如果添加完之后头文件报错的话,我们需要把上面的给注释掉,如果没有,则不需要注释
idea配置ssm框架(详细信息,全部流程)idea配置ssm框架(详细信息,全部流程)

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <!-- 1.启动spring容器,加载spring配置文件applicationContext.xml -->
  <!-- needed for ContextLoaderListener -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>

  <!-- Bootstraps the root web application context before servlet initialization -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 2.  配置spring mvc 的前端控制器,DispatcherServlet类拦截所有请求,交给controller处理
    加载spring mvc配置文件(dispatcherServlet-servlrt.xml,还没有建) -->
  <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--  不写,写的话需要建个springmvc.xml就不需要dispatcherServlet-servlet.xml -->
    <!--    <init-param>-->
    <!--      <param-name>contextConfigLocation</param-name>-->
    <!--      <param-value>classpath:springmvc.xml</param-value>-->
    <!--    </init-param>-->
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Map all requests to the DispatcherServlet for handling -->
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 编码过滤器,防止出现乱码 -->
  <filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

下面开始配dispatcherServlet-servlet.xml文件
1.配置spring mvc,作用主要就是充当控制器,只需要扫描controller
idea配置ssm框架(详细信息,全部流程)

<!-- spring mvc主要作用就是充当控制器,只需要扫描controller -->
<context:component-scan base-package="com.wu" use-default-filters="false">
    <!-- 因为是spring mvc 只需要扫描控制器 -->
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

2.配置试图解析器
idea配置ssm框架(详细信息,全部流程)

<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

3.两个标准配置,就是讲spring mvc不能处理的请求交给tomcat,例如静态资源,不需要访问controller的资源

<!-- 两个标准配置 -->
<!-- 将springmvc 不能处理的请求交给tomcat  例如静态资源 -->
<mvc:default-servlet-handler/>

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
    </mvc:message-converters>
</mvc:annotation-driven>

如果报红色的话,那你是关键字没有引入alt+Enter键
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- spring mvc主要作用就是充当控制器,只需要扫描controller -->
    <context:component-scan base-package="com.wu" use-default-filters="false">
        <!-- 因为是spring mvc 只需要扫描控制器 -->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!-- 配置视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!-- 两个标准配置 -->
    <!-- 将springmvc 不能处理的请求交给tomcat  例如静态资源 -->
    <mvc:default-servlet-handler/>

    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
        </mvc:message-converters>
    </mvc:annotation-driven>
</beans>

下面开始配置applicationContext.xml配置文件
1.Spring配置文件主要和配置和业务逻辑有关的

<context:property-placeholder location="classpath:dbconfig.properties"/>

2.数据源,连接数据库

<!-- 数据源 -->
<bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
    <property name="driverClass" value="${jdbc.driverClass}"></property>
    <property name="user" value="${jdbc.user}"></property>
    <property name="password" value="${jdbc.password}"></property>
</bean>

下图为红色的我们需要创建配置,帮我们连接数据库
idea配置ssm框架(详细信息,全部流程)

idea配置ssm框架(详细信息,全部流程)

里面填写你数据库的连接方式
idea配置ssm框架(详细信息,全部流程)

#数据库连接,使用的mysql数据库

jdbc.jdbcUrl=jdbc:mysql://localhost:3306/journalism_school?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
#加载驱动
jdbc.driverClass=com.mysql.cj.jdbc.Driver
#数据库登录用户名
jdbc.user=root
#密码
jdbc.password=root

重新返回applivationContext.xml配置文件
配置和mtbatis的整合

<!-- 配置和mybatis的整合 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 指定mybatis 全局配置文件的位置 -->
    <property name="configLocation" value="classpath:mybatis-config.xml"></property>
    <property name="dataSource" ref="pooledDataSource"></property>
    <!-- 指定mybatismapper文件的位置 -->
    <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean>

idea配置ssm框架(详细信息,全部流程)

创建一个mybatis-config.xml和mapper文件
idea配置ssm框架(详细信息,全部流程)

<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <!--分页-->
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
    </plugins>

</configuration>

在返回applicationContext.xml文件,可以先将其注销
在后期,如果我们如果需要手写sql语句,则将其去消注销

idea配置ssm框架(详细信息,全部流程)

在配置扫描器
idea配置ssm框架(详细信息,全部流程)

在配置上事务控制的配置
idea配置ssm框架(详细信息,全部流程)

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <!-- 控制数据源 -->
    <property name="dataSource" ref="pooledDataSource"></property>
</bean>

<aop:config>
    <!-- 切入点表达式 -->
    <aop:pointcut expression="execution(* com.wu.service..*(..) )" id="txPoint"/>
    <!-- 配置事务 -->
    <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
</aop:config>
<!-- 配置事务增强  事务如何切入 -->
<tx:advice id="txAdvice">

    <tx:attributes>
        <!-- 所有方法都是事务方法 -->
        <tx:method name="*"/>
        <!-- 以get开头的所有方法 -->
        <tx:method name="get*" read-only="true"/>
    </tx:attributes>
</tx:advice>

<!-- 定时任务 -->
<task:annotation-driven/>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
      http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
      http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    <!-- spring 配置文件  主要配置和业务逻辑有关的 -->
    <context:property-placeholder location="classpath:dbconfig.properties"/>
    <!-- 数据源 -->
    <bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
        <property name="driverClass" value="${jdbc.driverClass}"></property>
        <property name="user" value="${jdbc.user}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>
    <context:component-scan base-package="com.wu">
        <!-- 不能扫描控制器 -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>

    <!-- 配置和mybatis的整合 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 指定mybatis 全局配置文件的位置 -->
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <property name="dataSource" ref="pooledDataSource"></property>
        <!-- 指定mybatismapper文件的位置 -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
    </bean>

    <!-- 配置扫描器,将mybatis接口的实现加入到ioc容器中 -->
    <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 扫描所有的dao接口 -->
        <property name="basePackage" value="com.wu.dao"></property>
    </bean>

    <!-- 事务控制的配置 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 控制数据源 -->
        <property name="dataSource" ref="pooledDataSource"></property>
    </bean>

    <aop:config>
        <!-- 切入点表达式 -->
        <aop:pointcut expression="execution(* com.wu.service..*(..) )" id="txPoint"/>
        <!-- 配置事务 -->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
    </aop:config>
    <!-- 配置事务增强  事务如何切入 -->
    <tx:advice id="txAdvice">

        <tx:attributes>
            <!-- 所有方法都是事务方法 -->
            <tx:method name="*"/>
            <!-- 以get开头的所有方法 -->
            <tx:method name="get*" read-only="true"/>
        </tx:attributes>
    </tx:advice>

    <!-- 定时任务 -->
    <task:annotation-driven/>

</beans>

下面在配置Tomcat
点击右上角
idea配置ssm框架(详细信息,全部流程)idea配置ssm框架(详细信息,全部流程)idea配置ssm框架(详细信息,全部流程)idea配置ssm框架(详细信息,全部流程)
idea配置ssm框架(详细信息,全部流程)
idea配置ssm框架(详细信息,全部流程)
idea配置ssm框架(详细信息,全部流程)idea配置ssm框架(详细信息,全部流程)

idea配置ssm框架(详细信息,全部流程)

点击启动Tomcat,如果没有报错,则会显示这个页面
idea配置ssm框架(详细信息,全部流程)

idea配置ssm框架(详细信息,全部流程)相关教程

  1. Spring Boot入门系列(六)Spring Boot如何使用Mybatis XML 配置
  2. Virtual Machine Manager 2012 R2创建SQL 配置文件
  3. Windows Azure Pack集成配置SPF
  4. 不同IDEA版本启动Tomcat日志乱码[log4j]问题解决
  5. Linux配置多台tomcat
  6. IDEA安装完插件Scala后 通过add frameworks support找到不到scal
  7. CCNA配置试验五 vlan的基本配置
  8. SSM分布式项目之淘淘商城-第七天(IDEA)