亲宝软件园·资讯

展开

SSM 整合的配合文件 SSM 整合的配合文件(分享)

深夜行者 人气:0
想了解SSM 整合的配合文件(分享)的相关内容吗,深夜行者在本文为您仔细讲解SSM 整合的配合文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:SSM,整合,配合,文件,下面大家一起来学习吧。

1.1 maven项目pom管理

<!--常量和版本号-->
<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 <commons.beanutils>1.9.3</commons.beanutils>
 <spring.version>4.3.2.RELEASE</spring.version>
 <aspectj.version>1.8.6</aspectj.version>
 <aspectj.weaver>1.8.6</aspectj.weaver>
 <mybatis.spring.version>1.3.0</mybatis.spring.version>
 <mybatis.version>3.4.5</mybatis.version>
 <mysql.version>5.1.32</mysql.version>
 <slf4j.version>1.7.25</slf4j.version>
 <slf4j.log4j12.version>1.7.25</slf4j.log4j12.version>
 <log4j.version>1.2.17</log4j.version>
 <log4j.core.version>2.3</log4j.core.version>
 <commons.logging.version>1.2</commons.logging.version>
 <junit.version>4.12</junit.version>
 <commons-fileupload.version>1.3.1</commons-fileupload.version>
 <druid.version>1.0.13</druid.version>
 <jstl.version>1.2</jstl.version>
 <jsp-api.version>2.0</jsp-api.version>
 <jackson.version>2.9.2</jackson.version>
</properties>

<dependencies>
 <!--数据连接池-->
 <dependency>
 <groupId>com.alibaba</groupId>
 <artifactId>druid</artifactId>
 <version>${druid.version}</version>
 </dependency>
 <dependency>
 <groupId>commons-beanutils</groupId>
 <artifactId>commons-beanutils</artifactId>
 <version>${commons.beanutils}</version>
 </dependency>
 <!-- spring-core -->
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-core</artifactId>
 <version>${spring.version}</version>
 </dependency>
 <!-- spring-context -->
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-context</artifactId>
 <version>${spring.version}</version>
 </dependency>
 <!-- Spring AOP -->
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-aop</artifactId>
 <version>${spring.version}</version>
 </dependency>
 <!-- AspectJ Runtime -->
 <dependency>
 <groupId>org.aspectj</groupId>
 <artifactId>aspectjrt</artifactId>
 <version>${aspectj.version}</version>
 </dependency>
 <!-- AspectJ Weaver -->
 <dependency>
 <groupId>org.aspectj</groupId>
 <artifactId>aspectjweaver</artifactId>
 <version>${aspectj.weaver}</version>
 </dependency>
 <!-- Spring Jdbc 的支持 -->
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-jdbc</artifactId>
 <version>${spring.version}</version>
 </dependency>
 <!-- SpringMVC -->
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-webmvc</artifactId>
 <version>${spring.version}</version>
 </dependency>

 <!-- mybatis-spring 整合 -->
 <dependency>
 <groupId>org.mybatis</groupId>
 <artifactId>mybatis-spring</artifactId>
 <version>${mybatis.spring.version}</version>
 </dependency>
 <!-- Jackson Json处理工具包 -->
 <dependency>
 <groupId>com.fasterxml.jackson.core</groupId>
 <artifactId>jackson-databind</artifactId>
 <version>${jackson.version}</version>
 </dependency>
 <!-- mybatis -->
 <dependency>
 <groupId>org.mybatis</groupId>
 <artifactId>mybatis</artifactId>
 <version>${mybatis.version}</version>
 </dependency>

 <!-- MySql -->
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>${mysql.version}</version>
 </dependency>


 <!-- 文件上传组件 -->
 <dependency>
 <groupId>commons-fileupload</groupId>
 <artifactId>commons-fileupload</artifactId>
 <version>${commons-fileupload.version}</version>
 </dependency>
 <!-- JSP相关 -->
 <dependency>
 <groupId>jstl</groupId>
 <artifactId>jstl</artifactId>
 <version>${jstl.version}</version>
 </dependency>
 <dependency>
 <groupId>javax.servlet</groupId>
 <artifactId>jsp-api</artifactId>
 <version>${jsp-api.version}</version>
 <scope>provided</scope>
 </dependency>
 <!-- Test dependencies -->
 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>${junit.version}</version>
 <scope>test</scope>
 </dependency>
</dependencies>
<build>
 <defaultGoal>install</defaultGoal>
 <plugins>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.6.1</version>
  <configuration>
  <source>1.8</source>
  <target>1.8</target>
  </configuration>
 </plugin>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.2</version>
  <configuration>
  <encoding>UTF-8</encoding>
  </configuration>
 </plugin>
 </plugins>
 <!--IDEA编译src的java文件,而目录下的xml文件并不会一起打包,需要手动指定哪些配置文件需要读取-->
 <resources>
 <resource>
  <directory>src/main/java</directory>
  <includes>
  <include>**/*.xml</include>
  </includes>
 </resource>
 </resources>
</build>

1.2 Web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://java.sun.com/xml/ns/javaee"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="WebApp_ID" version="3.0">
 <display-name>ssm</display-name>
 <!-- 编码过滤器 -->
 <filter>
 <filter-name>characterEncoding</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>
 <init-param>
  <param-name>forceEncoding</param-name>
  <param-value>true</param-value>
 </init-param>
 </filter>
 <filter-mapping>
 <filter-name>characterEncoding</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!--//End 编码过滤器 -->

 <!-- 将POST请求转化为DELETE或者是PUT 要用_method指定真正的请求参数 -->
 <filter>
 <filter-name>HttpMethodFilter</filter-name>
 <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>HttpMethodFilter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter>
 <filter-name>HiddenHttpMethodFilter</filter-name>
 <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>HiddenHttpMethodFilter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- SpringMVC -->
 <servlet>
 <servlet-name>springmvc</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <init-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:springmvc.xml</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
 <servlet-name>springmvc</servlet-name>
 <url-pattern>*.shtml</url-pattern>
 </servlet-mapping>
 <!-- //End SpringMVC -->
 <welcome-file-list>
 <welcome-file>index.shtml</welcome-file>
 <welcome-file>index.htm</welcome-file>
 <welcome-file>index.jsp</welcome-file>
 <welcome-file>default.html</welcome-file>
 <welcome-file>default.htm</welcome-file>
 <welcome-file>default.jsp</welcome-file>
 </welcome-file-list>
</web-app>

1.3 springmvc配置文件

<?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:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="
  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.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 <!-- 包扫描 -->
 <context:component-scan base-package="cn.itcast"/>

 <!--视图解析器配置-->
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/jsp/" />
  <property name="suffix" value=".jsp" />
 </bean>
 <!-- 文件上传解析器 -->
 <bean id="multipartResolver"
   class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <!-- 最大允许上传文件大小,单位byte -->
  <property name="maxUploadSize" value="100000000"/>
 </bean>

 <!--引入spring配置-->
 <import resource="spring.xml" />
</beans>

1.4 spring配置文件

<?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:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xsi:schemaLocation="
  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.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop.xsd">
 <!-- 解析jdbc配置文件 -->
 <context:property-placeholder location="classpath:jdbc.properties" />
 <!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean
  below) 事务传播特性配置 -->
 <tx:advice id="txAdvice" transaction-manager="txManager">
  <!-- the transactional semantics... -->
  <tx:attributes>
   <tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT"
      rollback-for="java.lang.Exception" />
   <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"
      rollback-for="java.lang.Exception" />
   <tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT"
      rollback-for="java.lang.Exception" />
   <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"
      rollback-for="java.lang.Exception" />
   <tx:method name="modify*" propagation="REQUIRED" isolation="DEFAULT"
      rollback-for="java.lang.Exception" />
   <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"
      rollback-for="java.lang.Exception" />
   <!-- 查询方法 -->
   <tx:method name="query*" read-only="true" />
   <tx:method name="select*" read-only="true" />
   <tx:method name="find*" read-only="true" />
  </tx:attributes>
 </tx:advice>

 <!-- 配置事务管理器 -->
 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
 </bean>

 <!-- 数据库基本信息配置 -->
 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  <property name="driverClassName" value="${jdbc.driver}" />
  <property name="url" value="${jdbc.url}" />
  <property name="username" value="${jdbc.username}" />
  <property name="password" value="${jdbc.pwd}" />
 </bean>
 <!-- 声明式事务AOP配置 -->
 <aop:config>
  <aop:pointcut expression="execution(* cn.itcast.service.impl.*.*(..))" id="tranpointcut" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="tranpointcut" />
 </aop:config>

 <!--SqlSessionFactoryBean的配置-->
 <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
  <!--
   MyBatis别名
   MyBatis配置文件
   MyBatis配置映射文件
   指定数据源
   -->
  <property name="typeAliasesPackage" value="cn.itcast.model" />
  <property name="configLocation" value="classpath:mybatis.xml" />
  <property name="mapperLocations">
   <array>
    <value>classpath:cn/itcast/mapper/*Mapper.xml</value>
   </array>
  </property>
  <property name="dataSource" ref="dataSource"/>
 </bean>

 <!--包扫描-->
 <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  <!--指定对应接口的包路径-->
  <property name="basePackage" value="cn.itcast.mapper" />
  <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean" />
 </bean>

</beans>

1.5 JDBC配置文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/crm?useUnicode=true&characterEncoding=utf8&autoReconnect=true
jdbc.username=root
jdbc.pwd=123456

1.6 Log4j配置文件

log4j.rootLogger=DEBUG,A1
log4j.logger.com.taotao = DEBUG
log4j.logger.org.mybatis = DEBUG
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n

1.7 MyBatis配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
 PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>

以上这篇SSM 整合的配合文件(分享)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

加载全部内容

相关教程
猜你喜欢
用户评论