ssm整合详细xml配置

ssm即spring,springmvc,myBatis三个框架整合在一起,融会贯通

整合步骤如下:

1.创建maven工程,在pom.xml配置文件中导入相关依赖

<!--properties中配置版本信息-->
<properties>
  <!--编码格式-->
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <!--编译版本-->
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
 
  <!--导入依赖的相关版本号,可自行更改-->
  <junit.version>4.12</junit.version>
  <spring.version>5.0.3.RELEASE</spring.version>
  <druid.version>1.1.2</druid.version>
  <jstl.version>1.2</jstl.version>
  <servlet-api.version>4.0.0</servlet-api.version>
  <jsp-api.version>2.3.1</jsp-api.version>
  <commons-fileupload.version>1.3.3</commons-fileupload.version>
  <ehcache.version>2.10.4</ehcache.version>
  <oracle.version>12.1.0.1-atlassian-hosted</oracle.version>
  <slf4j.version>1.7.25</slf4j.version>
  <mybatis.version>3.4.5</mybatis.version>
  <pagehelper.version>5.1.2</pagehelper.version>
  <mybatis-ehcache.version>1.0.0</mybatis-ehcache.version>
  <mybatis-generator-core.version>1.3.5</mybatis-generator-core.version>
  <maven-plugin-api.version>3.5.0</maven-plugin-api.version>
  <mybatis.spring.version>1.3.1</mybatis.spring.version>
  <jackson.version>2.9.0</jackson.version>
  <shiro.version>1.4.0</shiro.version>

</properties>

<dependencies>


  <!--org.aspectj aop注解-->
  <dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.8.13</version>
  </dependency>
  <dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.8.10</version>
  </dependency>
  <!-- 缓存 -->
  <dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>${ehcache.version}</version>
  </dependency>
  <!-- oracle -->
  <dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>${oracle.version}</version>
  </dependency>
  <!-- JSP相关 -->
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>${jstl.version}</version>
  </dependency>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>${servlet-api.version}</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>javax.servlet.jsp-api</artifactId>
    <version>${jsp-api.version}</version>
    <scope>provided</scope>
  </dependency>
  <!-- 文件上传组件 -->
  <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>${commons-fileupload.version}</version>
  </dependency>
  <!--单元测试jar-->
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
  </dependency>

  <!--spring mvc -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>${spring.version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.version}</version>
  </dependency>


  <!-- Spring web依赖 -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
  </dependency>

  <!-- Spring整合ORM框架依赖 -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring.version}</version>
    <scope>test</scope>
  </dependency>

  <!--spring websocket 模块-->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-websocket</artifactId>
    <version>${spring.version}</version>
  </dependency>

  <!-- 数据库连接池 -->
  <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>${druid.version}</version>
  </dependency>

  <!-- 日志处理 log4j-->
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>${slf4j.version}</version>
  </dependency>

  <!-- Mybatis -->
  <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>${mybatis.version}</version>
  </dependency>

  <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-ehcache</artifactId>
    <version>${mybatis-ehcache.version}</version>
  </dependency>

  <!--mybatis spring 集成jar-->
  <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>${mybatis.spring.version}</version>
  </dependency>

  <!-- mybatis反向建模 -->
  <dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-plugin-api</artifactId>
    <version>${maven-plugin-api.version}</version>
  </dependency>
  <dependency>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-core</artifactId>
    <version>${mybatis-generator-core.version}</version>
  </dependency>

  <!--json处理-->
  <!--实际上为三个包,但是导入databind会自动导入其他两个包-->
  <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>${jackson.version}</version>
  </dependency>
  <!--mybatis分页插件-->
  <dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>${pagehelper.version}</version>
  </dependency>
  <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>3.2.12</version>
  </dependency>






  <!-- Shiro权限管理 -->
  <!--    <dependency>-->
  <!--      <groupId>org.apache.shiro</groupId>-->
  <!--      <artifactId>shiro-web</artifactId>-->
  <!--      <version>${shiro.version}</version>-->
  <!--    </dependency>-->
  <!--    <dependency>-->
  <!--      <groupId>org.apache.shiro</groupId>-->
  <!--      <artifactId>shiro-spring</artifactId>-->
  <!--      <version>${shiro.version}</version>-->
  <!--    </dependency>-->
  <!--    <dependency>-->
  <!--      <groupId>org.apache.shiro</groupId>-->
  <!--      <artifactId>shiro-ehcache</artifactId>-->
  <!--      <version>${shiro.version}</version>-->
  <!--    </dependency>-->
  <!--    <dependency>-->
  <!--      <groupId>org.apache.shiro</groupId>-->
  <!--      <artifactId>shiro-quartz</artifactId>-->
  <!--      <version>${shiro.version}</version>-->
  <!--    </dependency>-->
  <!--    <dependency>-->
  <!--      <groupId>org.codehaus.jackson</groupId>-->
  <!--      <artifactId>jackson-mapper-asl</artifactId>-->
  <!--      <version>1.9.13</version>-->
  <!--    </dependency>-->
</dependencies>


<build>
  <finalName>ssm</finalName>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.1.0</version>
      </plugin>
      <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>
  <plugins>
    <!--mybatis代码生成插件-->
    <plugin>
      <groupId>org.mybatis.generator</groupId>
      <artifactId>mybatis-generator-maven-plugin</artifactId>
      <version>1.3.5</version>
      <configuration>
        <verbose>true</verbose>
        <overwrite>true</overwrite>
      </configuration>
    </plugin>

    <plugin>
      <groupId>org.mybatis.generator</groupId>
      <artifactId>mybatis-generator-maven-plugin</artifactId>
      <version>1.3.5</version>
      <configuration>
        <!--配置文件的路径-->
      <dependencies>
        <dependency>
          <groupId>com.oracle</groupId>
          <artifactId>ojdbc6</artifactId>
          <version>${oracle.version}</version>
        </dependency>
        <!--<dependency>-->
        <!--<groupId>mysql</groupId>-->
        <!--<artifactId>mysql-connector-java</artifactId>-->
        <!--<version>5.1.46</version>-->
        <!--</dependency>-->
      </dependencies>
    </plugin>


  </plugins>


  <resources>
    <resource>
      <!-- 配置打war时候的要打的文件路径 -->
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.xml</include>
      </includes>
      <filtering>false</filtering>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
      <includes>
        <include>*.properties</include>
        <include>*.xml</include>
      </includes>
      <filtering>false</filtering>
    </resource>
  </resources>
</build>

2.配置spring,在resources中新建applicationContext.xml配置文件,代码如下

<?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:context="http://www.springframework.org/schema/context"
       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/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">
    <!--设置扫描包,扫描对应包下的注解,一般扫描 mapper,service,aop层的注解-->
    <context:component-scan base-package="com.seecen.mapper,com.seecen.dao,com.seecen.service,com.seecen.aop"/>

    <!--
        配置数据库连接池
        此处使用阿里的druid连接池,功能强大,性能优秀
         c3p0 也是一种连接池,以前项目用的比较多。
         这里配置的oracle
    -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close" >
        <!--${url}为引用jdbc.properties中的url配置-->
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
        <property name="username" value="用户名"/>
        <property name="password" value="密码"/>
        <!--初始连接大小-->
        <property name="initialSize" value="5"/>
        <!--最小连接数,连接池至少需要保持的连接数-->
        <property name="minIdle" value="5"/>
        <!--最大连接数-->
        <property name="maxActive" value="20"/>
        <!--配置最大等待时间-->
        <property name="maxWait" value="60000"/>
        <!--最大空闲时间-->
        <property name="minEvictableIdleTimeMillis" value="300000"/>
        <!--连接空闲时间超过最大空闲时间时,执行validationQuery验证连接是否可用-->
        <property name="testWhileIdle" value="true"/>
        <!--验证连接是否可用-->
        <property name="validationQuery" value="select 1 from dual"/>
    </bean>

    <!--整合mybatis-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--注入数据源-->
        <property name="dataSource" ref="dataSource"/>
        <!--指定mybatis主配置文件路径-->
        <property name="configLocation" value="classpath:mybatis.xml"/>
        <!--指定mapper.xml文件路径-->
        <property name="mapperLocations"
                  value="classpath:com/seecen/mapper/*.xml"/>
    </bean>

    <!-- 整合mybatis 配置dao层接口,交由spring创建对象-->
    <bean  class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--指定mybatis dao层接口目录-->
        <property name="basePackage" value="mapper接口路径"/>
        <!--注入sqlsessionFactory-->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!--配置事务管理器-->
    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--配置datasource-->
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--以注解方式配置事务-->
    <!--<tx:annotation-driven/>-->
    <!--以xml配置AOP的方式-->
    <!--配置事务传播特性和 事务隔离级别-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <!--配置事务传播特性 method为方法名, propagation配置事务传播特性
            事务的七大传播特性:
                 1.REQUIRED:方法必须运行在一个事务中,如果不存在事务则创建一个事务,有异常都回滚
                 2.SUPPORTS:支持事务但不要求必须有事务
                 3.MANDATORY:必须有事务,没有则抛出异常
                 4.REQUIRES_NEW:要求有自己的新的事务,必须运行在自己的事务中,如果外层有事务则将其挂起。
                 5.NOT_SUPPORTED:不支持事务,有事务则不运行
                 6.NEVER:不支持事务,有事务则抛出异常
                 7.NESTED:嵌套事务,可以多个事务嵌套在一起,内部事务不会影响外部事务
             isolation="" 指定事务隔离级别-->
            <!-- name:指定切入点的方法名,匹配的方法才能够指定到事务传播特性和隔离级别-->
            <tx:method name="save*" propagation="REQUIRED"  isolation="READ_COMMITTED" />
            <tx:method name="insert*" propagation="NESTED" isolation="SERIALIZABLE"/>
            <tx:method name="update*" propagation="REQUIRED"  isolation="READ_COMMITTED" />
            <!-- oracle数据库只支持读已提交和串行化两种事务隔离级别,默认读已提交-->
            <tx:method name="delete*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <!--查询操作 配置read-only=true,标识为只读事务。-->
            <tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" />
            <tx:method name="get*" propagation="REQUIRED" read-only="true" />
            <tx:method name="select*" propagation="REQUIRED" read-only="true" />
        </tx:attributes>
    </tx:advice>

    <!--aop配置事务-->
    <aop:config>
        <!--切入点,将事务切入到service层方法-->
        <aop:pointcut id="pointcut" expression="execution(* com.seecen.service.*.*(..))"/>
        <!--<aop:advisor>配置事务切面-->
        <!--aop:advisor配置直接实现对应接口的切面aop-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
    </aop:config>
</beans>

3.配置springmvc,创建springmvc.xml文件,代码如下:

<?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"
       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/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 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--开启注解驱动-->
    <mvc:annotation-driven/>
    <!--配置扫描包,扫描controller层的注解-->
    <context:component-scan base-package="controller"/>

    <!--配置注解式AOP支持  proxy-target-class="true" 申明使用cglib动态代理-->
    <aop:aspectj-autoproxy proxy-target-class="true"/>

    <!--配置视图解析器-->
    <!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
    <!--&lt;!&ndash;配置视图的前缀&ndash;&gt;-->
    <!--<property name="prefix" value="/WEB-INF/pages" />-->
    <!--&lt;!&ndash;配置视图后缀&ndash;&gt;-->
    <!--<property name="suffix" value=".jsp" />-->
    <!--</bean>-->


    <!--     配置springmvc拦截器-->
<!--    <mvc:interceptors>-->
<!--        <mvc:interceptor>-->
<!--            &lt;!&ndash; 定义需要拦截的请求 /**表示任意控制层请求 /*一级请求 /**拦截多级请求&ndash;&gt;-->
<!--            <mvc:mapping path="/**"/>-->
<!--            &lt;!&ndash; 定义不拦截的请求&ndash;&gt;-->
<!--            <mvc:exclude-mapping path="/static/**"/>-->
<!--            <mvc:exclude-mapping path="/login/loginByCode"/>-->
<!--            <mvc:exclude-mapping path="/login/getVerifyCode"/>-->
<!--            &lt;!&ndash; 配置拦截器类-->
<!--                顺序有关系,在上面的先执行!!!-->
<!--            &ndash;&gt;-->
<!--            <bean class=""/>-->
<!--        </mvc:interceptor>-->
<!--        &lt;!&ndash;        &lt;!&ndash; 权限拦截器&ndash;&gt;&ndash;&gt;-->
<!--        &lt;!&ndash;        <mvc:interceptor>&ndash;&gt;-->
<!--        &lt;!&ndash;            <mvc:mapping path="/**/"/>&ndash;&gt;-->
<!--        &lt;!&ndash;            <bean id="permissionInterceptor" class="com.seecen.aop.PermissionInterceptor"></bean>&ndash;&gt;-->
<!--        &lt;!&ndash;        </mvc:interceptor>&ndash;&gt;-->
<!--    </mvc:interceptors> -->

<!--    &lt;!&ndash;配置文件上传&ndash;&gt;-->
<!--    <bean id="multipartResolver"-->
<!--          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">-->
<!--        &lt;!&ndash;设置文件编码格式&ndash;&gt;-->
<!--        <property name="defaultEncoding" value="UTF-8"/>-->
<!--        &lt;!&ndash;设置最大上传大小&ndash;&gt;-->
<!--        <property name="maxUploadSize" value="10240000" />-->

<!--    </bean>-->
<!--    &lt;!&ndash;开启默认servlet,用以处理静态资源文件&ndash;&gt;-->
<!--    <mvc:default-servlet-handler/>-->

    <!-- 资源映射 将请求地址映射到某个目录或具体的磁盘路径下-->
    <!-- mapping 配置请求地址 location 配置文件路径-->
    <!-- head开头的任意路径-->
    <!--配置customer客户的文件请求地址 -->
<!--    <mvc:resources mapping="/customerFile/**" location="file:D:/crmsFile/"></mvc:resources>-->
    <!--    <mvc:resources mapping="/articleImg/**" location="file:D:/articleImg/"></mvc:resources>-->
    <!--    &lt;!&ndash;请求地址为headimg/logo.png==>/WEB-INF/img/logo.png &ndash;&gt;-->
    <!--    <mvc:resources mapping="/headimg/**" location="/WEB-INF/img/"></mvc:resources>-->
    <!--   -->



    <!--    &lt;!&ndash;设置启用shiro注解&ndash;&gt;
        <aop:config proxy-target-class="true"></aop:config>

        &lt;!&ndash;配置shiro 权限拦截器&ndash;&gt;
        <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
            <property name="securityManager" ref="securityManager"></property>
        </bean>-->

    <!--
        &lt;!&ndash;配置springmvc异常处理机制&ndash;&gt;
        <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            &lt;!&ndash;异常映射规则&ndash;&gt;
            <property name="exceptionMappings">
                <props >
                    &lt;!&ndash;key指定异常类&ndash;&gt;
                    <prop key="org.apache.shiro.authz.UnauthorizedException">
                        nopermission.jsp
                    </prop>
                </props>
            </property>
        </bean>-->

</beans>

4.配置mybatis,创建mybatis.xml文件,代码如下

<?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>
   <settings>
      <!--配置日志实现-->
      <setting name="logImpl" value="STDOUT_LOGGING" />
      <!--一级缓存二级缓存-->
      <!--开启二级缓存-->
      <setting name="cacheEnabled" value="true"/>

   </settings>


   <!--mybatis分页插件-->
  <!-- <plugins>
      <plugin interceptor="com.github.pagehelper.PageInterceptor">
         <!--pageSize=0时,是否查询出全部结果,默认为false-->
         <property name="pageSizeZero" value="true" />
         <!--分页合理化参数,默认文false;pageNum<=0,查询第一页;pageNum>总页数,查询最后一页-->
         <property name="reasonable" value="true" />
         <property name="params"
                 value="pageNum=pageHelperStart;pageSize=pageHelperRows;" />
         <property name="supportMethodsArguments" value="false" />
         <property name="returnPageInfo" value="none" />
      </plugin>
   </plugins> -->


</configuration>

5.配置log4j日志,创建log4j.properties文件,代码如下

#\u751F\u4EA7\u73AF\u5883\u4F7F\u7528info
#log4j.rootLogger = info,stdout,logfile
#\u5F00\u53D1\u73AF\u5883\u4F7F\u7528debug
log4j.rootLogger = info,stdout,logfile

log4j.logger.com.seecen.system.aop.advice = trace,aop
#\u5B9A\u4E49\u4E00\u4E2A\u65E5\u5FD7\u8F93\u51FA\u8DEF\u5F84
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %p [%C].%M(%L) --> %m%n

log4j.appender.logfile = org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.Threshold = ERROR
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd
# \u6307\u5B9A\u6587\u4EF6\u5B58\u50A8\u8DEF\u5F84
log4j.appender.logfile.File = D:/ssmlogfile.log
# layout \u6307\u5B9A\u683C\u5F0F
log4j.appender.logfile.layout = org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %p [%C].%M(%L) --> %m%n
log4j.appender.logfile.Append=true

log4j.appender.aop = org.apache.log4j.DailyRollingFileAppender
log4j.appender.aop.File = D:/ssmlogfileAOP.log
log4j.appender.aop.layout = org.apache.log4j.PatternLayout
log4j.appender.aop.layout.ConversionPattern =%d{yyyy-MM-dd HH\:mm\:ss} %m%n
log4j.appender.aop.Append=true

6.配置web.xml文件,代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
        version="3.0"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

  <display-name>ssm</display-name>

  <!--编码过滤器  用来统一设置request和response的编码格式 -->
  <filter>
    <filter-name>encodingFilter</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>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!--log4j 日志配置-->
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath*:log4j.properties</param-value>
  </context-param>

  <context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>60000</param-value>
  </context-param>

  <!--配置spring-->
  <!--指定spring的配置文件路径-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext*.xml</param-value>
  </context-param>
  <!-- 配置spring监听器,会在容器启动的时候加载spring容器-->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!--配置shiro-->
  <!--<filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      &lt;!&ndash;配置shiro过滤器的bean的名称&ndash;&gt;
      <param-name>targetBeanName</param-name>
      <param-value>shiroFilter</param-value>
    </init-param>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>shiroFilter</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>/</url-pattern>
  </servlet-mapping>

</web-app>

配置好后运行tomcat,如下显示,开启编写代码之旅吧!在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值