• Spring需要的几个关键配置文件(SSM框架整合)


    打包下载


     

    springmvc-servlet.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xmlns:mvc="http://www.springframework.org/schema/mvc"
     5     xmlns:p="http://www.springframework.org/schema/p"
     6     xmlns:context="http://www.springframework.org/schema/context"
     7     xsi:schemaLocation="
     8         http://www.springframework.org/schema/beans
     9         http://www.springframework.org/schema/beans/spring-beans.xsd
    10         http://www.springframework.org/schema/context
    11         http://www.springframework.org/schema/context/spring-context.xsd
    12         http://www.springframework.org/schema/mvc
    13         http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    14     <!-- 设置字符编码 -->
    15     <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
    16         <property name="supportedMediaTypes">
    17             <list>
    18                 <value>application/json;charset=UTF-8</value>
    19             </list>
    20         </property>
    21     </bean>
    22     <!-- 自动注册模型 -->
    23     <mvc:annotation-driven>
    24         <mvc:message-converters>
    25             <!-- 引用上面设置的字符编码 -->
    26             <ref bean="stringHttpMessageConverter"/>
    27         </mvc:message-converters>
    28     </mvc:annotation-driven>
    29     <!-- 放过静态资源 -->
    30     <mvc:default-servlet-handler/>
    31     <!-- 多视图解析器 -->
    32     <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    33         <!-- 指定json 用什么工具解析  xml 用什么工具解析 -->
    34         <property name="defaultViews">
    35             <list>
    36                 <bean class="com.alibaba.fastjson.support.spring.FastJsonJsonView">  
    37                     <property name="charset" value="UTF-8"/>  
    38                 </bean> 
    39                 <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
    40                     <constructor-arg>
    41                         <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    42                              <property name="classesToBeBound">
    43                                 <list>
    44                                    <value>com.appsys.pojo.Ad_promotion</value>
    45                                    <value>com.appsys.pojo.App_category</value>
    46                                    <value>com.appsys.pojo.App_info</value>
    47                                    <value>com.appsys.pojo.App_version</value>
    48                                    <value>com.appsys.pojo.Backend_user</value>
    49                                    <value>com.appsys.pojo.Data_dictionary</value>
    50                                    <value>com.appsys.pojo.Dev_user</value>
    51                                 </list>
    52                              </property>
    53                         </bean>
    54                     </constructor-arg>
    55                 </bean>
    56             </list>
    57         </property>
    58         <!-- 指定 jsp解析器,完成视图的对应 -->
    59         <property name="viewResolvers">
    60              <list>
    61                  <bean    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    62                     <property name="prefix" value="/" />
    63                     <property name="suffix" value=".jsp" />
    64                 </bean>
    65              </list>
    66         </property>
    67     </bean>
    68     <!-- 扫描注解 -->
    69     <context:component-scan base-package="com.appsys.controller,com.appsys.service.impl" />
    70     <!-- 指定文件上传解析  名字不能乱给 -->
    71     <bean name="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    72         <property name="defaultEncoding" value="utf-8" />
    73         <property name="maxUploadSize" value="9223372036854775807" />
    74     </bean>
    75 </beans>

    applicationContext.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://www.springframework.org/schema/beans
     5     http://www.springframework.org/schema/beans/spring-beans.xsd">
     6     <!-- 创建数据源 -->
     7     <bean id="dataDasource" class="org.apache.commons.dbcp.BasicDataSource">
     8         <property name="driverClassName" value="com.mysql.jdbc.Driver" />
     9         <property name="url" value="jdbc:mysql://localhost:3306/appinfodb?characterEncoding=utf8&amp;useUnicode=true&amp;useSSL=true" />
    10         <property name="username" value="root" />
    11         <property name="password" value="111111" />
    12     </bean>
    13     <!-- 创建sqlsessionfactory会话工厂 -->
    14     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    15         <property name="dataSource" ref="dataDasource" />
    16         <property name="configLocation" value="classpath:mybatis-config.xml" />
    17         <property name="mapperLocations" value="classpath:mybatis-sqlmappers/*.xml" />
    18         <property name="typeAliasesPackage" value="com.appsys.pojo" />
    19     </bean>
    20     <!-- 映射mapper文件(mybatis-sql语句) -->
    21     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    22         <property name="basePackage" value="com.appsys.dao" />
    23         <property name="sqlSessionFactory" ref="sqlSessionFactory" />
    24     </bean>
    25 </beans>

    web.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app version="3.0" 
     3     xmlns="http://java.sun.com/xml/ns/javaee" 
     4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     6     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
     7   <display-name></display-name>    
     8   <welcome-file-list>
     9     <welcome-file>index.jsp</welcome-file>
    10   </welcome-file-list>
    11   <!-- 指定Spring Bean的配置文件所在目录 
    12               在web.xml中通过contextConfigLocation配置spring,
    13        contextConfigLocation参数定义了要装入的 Spring 配置文件。 
    14   -->
    15     <context-param>
    16         <param-name>contextConfigLocation</param-name>
    17         <param-value>classpath:applicationContext.xml</param-value>
    18     </context-param>
    19   
    20      <!-- spring字符编码过滤器start-->
    21     <filter>
    22         <!--① Spring 编码过滤器 -->
    23       <filter-name>encodingFilter</filter-name>
    24       <filter-class>
    25           org.springframework.web.filter.CharacterEncodingFilter
    26       </filter-class>
    27       <!--② 编码方式  -->
    28       <init-param> 
    29           <param-name>encoding</param-name>
    30           <param-value>UTF-8</param-value>
    31       </init-param>
    32       <!--③ 强制进行编码转换 -->
    33       <init-param>
    34           <param-name>forceEncoding</param-name>
    35           <param-value>true</param-value>
    36       </init-param>
    37      </filter>
    38      <!-- ② 过滤器的匹配 URL -->
    39        <filter-mapping> 
    40            <filter-name>encodingFilter</filter-name>
    41            <url-pattern>/*</url-pattern>
    42        </filter-mapping>
    43     <!-- spring字符编码过滤器end-->
    44     
    45     <!-- Spring MVC配置 -->
    46     <servlet>
    47         <servlet-name>springmvc</servlet-name>
    48         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    49         <init-param>
    50             <param-name>contextConfigLocation</param-name>
    51             <param-value>classpath:springmvc-servlet.xml</param-value>
    52         </init-param>
    53         <load-on-startup>1</load-on-startup>
    54     </servlet>
    55     <servlet-mapping>
    56         <servlet-name>springmvc</servlet-name>
    57         <url-pattern>/</url-pattern>
    58     </servlet-mapping>
    59     
    60      <!-- Spring配置 -->
    61     <!-- 当系统启动的时候,spring需要进行一些资源加载或者配置,都需要使用此监听去做 -->
    62     <listener>
    63         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    64     </listener>
    65     
    66     <!-- log4j配置start -->
    67     <context-param>
    68         <param-name>log4jConfigLocation</param-name>
    69         <param-value>classpath:log4j.properties</param-value>
    70     </context-param>
    71     <context-param>
    72     <!-- 指定系统根目录路径 -->
    73         <param-name>webAppRootKey</param-name>
    74         <param-value>SMBMMVC.root</param-value>
    75        </context-param>
    76     <!-- Spring 加载 Log4j 的监听 -->
    77     <listener>
    78         <listener-class>
    79             org.springframework.web.util.Log4jConfigListener
    80         </listener-class>
    81     </listener>
    82     <!-- log4j配置end -->
    83 </web-app>

     log4j.properties

     1 log4j.rootLogger=debug,CONSOLE,file
     2 #log4j.rootLogger=ERROR,ROLLING_FILE
     3 
     4 log4j.logger.cn.smbms=debug
     5 log4j.logger.org.apache.ibatis=debug
     6 log4j.logger.org.mybatis.spring=debug
     7 log4j.logger.java.sql.Connection=debug
     8 log4j.logger.java.sql.Statement=debug
     9 log4j.logger.java.sql.PreparedStatement=debug
    10 log4j.logger.java.sql.ResultSet=debug
    11 
    12 ######################################################################################
    13 # Console Appender  u65e5u5fd7u5728u63a7u5236u8f93u51fau914du7f6e
    14 ######################################################################################
    15 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
    16 log4j.appender.Threshold=debug
    17 log4j.appender.CONSOLE.DatePattern=yyyy-MM-dd
    18 log4j.appender.CONSOLE.Target=System.out
    19 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
    20 log4j.appender.CONSOLE.layout.ConversionPattern= - (%r ms) - %d{yyyy-M-d HH:mm:ss}%x[%5p](%F:%L) %m%n
    21 
    22 
    23 
    24 ######################################################################################
    25 # Rolling File  u6587u4ef6u5927u5c0fu5230u8fbeu6307u5b9au5c3au5bf8u7684u65f6u5019u4ea7u751fu4e00u4e2au65b0u7684u6587u4ef6
    26 ######################################################################################
    27 #log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender
    28 #log4j.appender.ROLLING_FILE.Threshold=INFO
    29 #log4j.appender.ROLLING_FILE.File=${baojia.root}/logs/log.log
    30 #log4j.appender.ROLLING_FILE.Append=true
    31 #log4j.appender.ROLLING_FILE.MaxFileSize=5000KB
    32 #log4j.appender.ROLLING_FILE.MaxBackupIndex=100
    33 #log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout
    34 #log4j.appender.ROLLING_FILE.layout.ConversionPattern=%d{yyyy-M-d HH:mm:ss}%x[%5p](%F:%L) %m%n
    35 
    36 ######################################################################################
    37 # DailyRolling File  u6bcfu5929u4ea7u751fu4e00u4e2au65e5u5fd7u6587u4ef6uff0cu6587u4ef6u540du683cu5f0f:log2009-09-11
    38 ######################################################################################
    39 log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
    40 log4j.appender.file.DatePattern=yyyy-MM-dd
    41 log4j.appender.file.File=${AppInfoSystem.root}/logs/log.log
    42 log4j.appender.file.Append=true
    43 log4j.appender.file.Threshold=debug
    44 log4j.appender.file.layout=org.apache.log4j.PatternLayout
    45 log4j.appender.file.layout.ConversionPattern= - (%r ms) - %d{yyyy-M-d HH:mm:ss}%x[%5p](%F:%L) %m%n
    46 
    47 #DWR u65e5u5fd7
    48 #log4j.logger.org.directwebremoting = ERROR
    49 
    50 #u663eu793aHibernateu5360u4f4du7b26u7ed1u5b9au503cu53cau8fd4u56deu503c
    51 #log4j.logger.org.hibernate.type=DEBUG,CONSOLE 
    52 
    53 #log4j.logger.org.springframework.transaction=DEBUG
    54 #log4j.logger.org.hibernate=DEBUG
    55 #log4j.logger.org.acegisecurity=DEBUG
    56 #log4j.logger.org.apache.myfaces=TRACE
    57 #log4j.logger.org.quartz=DEBUG
    58 
    59 #log4j.logger.com.opensymphony=INFO  
    60 #log4j.logger.org.apache.struts2=DEBUG  
    61 log4j.logger.com.opensymphony.xwork2=debug

    mybatis-config.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>
        <!-- 设置mybatis运行行为 -->
        <settings>
            <!-- 设置日志实现为log4j -->
            <setting name="logImpl" value="LOG4J"/>
            <!-- 设置自动映射级别为全自动 -->
            <setting name="autoMappingBehavior" value="FULL"/>
        </settings>
    </configuration>
    欢迎提出意见或建议!!!
  • 相关阅读:
    Eureka 服务的注册和发现
    springcloud 中文文档
    mysql 7 种 join
    通用 mapper
    docker 容器操作( 以 tomcat 为例 )
    linux下安装phpunit简单方法
    图片优化的几个小工具
    安装基准测试工具sysbench
    安装pcntl以实现php多进程
    安装memcache及php的memcached模块
  • 原文地址:https://www.cnblogs.com/gaofei-1/p/7436169.html
Copyright © 2020-2023  润新知