欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-14 22:44:40
1.1 maven项目pom管理

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 整合的配合文件(分享)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:

下一篇: