SSM项目配置文件DEMO

SSM相关配置文件

<spring-mvc.xml>文件

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

<beans xmlns="http://www.springframework.org/schema/beans"

         xmlns:mvc="http://www.springframework.org/schema/mvc" 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:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"

         xsi:schemaLocation="http://www.springframework.org/schema/beans

         http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

         http://www.springframework.org/schema/mvc

         http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

         http://www.springframework.org/schema/context

         http://www.springframework.org/schema/context/spring-context-3.2.xsd

         http://www.springframework.org/schema/aop

         http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

         http://www.springframework.org/schema/task

    http://www.springframework.org/schema/task/spring-task-3.2.xsd">

         <context:component-scan base-package="<controller所在的包> " />

         <mvc:default-servlet-handler />

         <mvc:annotation-driven>

                  <mvc:message-converters register-defaults="true">

                          <bean

                                   class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">

                                   <property name="supportedMediaTypes">

                                            <list>

                                                     <value>text/html;charset=UTF-8</value>

                                                     <value>application/json</value>

                                                     <value>application/xml;charset=UTF-8</value>

                                            </list>

                                   </property>

                          </bean>

                  </mvc:message-converters>

         </mvc:annotation-driven>

 

         <mvc:interceptors>

                  <!-- 授权拦截 -->

                  <mvc:interceptor>

                 <mvc:mapping path="/**" />

                 <mvc:exclude-mapping path="/js/**" />

                          <mvc:exclude-mapping path="/css/**" />

                          <mvc:exclude-mapping path="/images/**" />

                          <mvc:exclude-mapping path="/fonts/**" />

                 <mvc:exclude-mapping path="/NoNeedInterceptor/**"/>

                 <bean id="PermissionInterceptor" class="com.publicutil.PermissionInterceptor"/> 

       </mvc:interceptor> 

         </mvc:interceptors>

         <!-- 增加定时任务插件 -->

         <context:annotation-config />

         <task:scheduler id="scheduler" pool-size="10" />

         <task:annotation-driven executor="scheduler" proxy-target-class="true" />

         <!--配置cglib代理 -->

         <aop:aspectj-autoproxy proxy-target-class="true" />

         <!-- 配置视图解析器 -->

         <bean

                  class="org.springframework.web.servlet.view.InternalResourceViewResolver">

                  <property name="prefix" value="/WEB-INF/jsp/"></property>

                  <property name="suffix" value=".jsp"></property>

         </bean>

         <!-- 文件上传 -->

         <bean id="multipartResolver"

                  class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

                  <property name="maxUploadSize" value="104857600" />

                  <property name="maxInMemorySize" value="4096" />

                  <property name="defaultEncoding" value="UTF-8"></property>

         </bean>

</beans>

<spring-mybatis.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: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-3.1.xsd     

                        http://www.springframework.org/schema/context     

                        http://www.springframework.org/schema/context/spring-context-3.1.xsd     

                        http://www.springframework.org/schema/mvc     

                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

         <!-- 自动扫描包 -->

         <context:component-scan base-package="<需要注入的bean的包> " />

         <!-- 引入配置文件 -->

         <bean id="propertyConfigurer"

                  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

                  <property name="locations">

                          <list>

                                   <value>classpath:config.properties</value>

                                   <value>classpath:log4j.properties</value>

                          </list>

                  </property>

         </bean>

         <!-- 配置数据源 -->

         <bean id="dataSource"

                  class="org.springframework.jdbc.datasource.DriverManagerDataSource">

                  <property name="driverClassName" value="${jdbc.driver}" />

                  <property name="url" value="${jdbc.url}" />

                  <property name="username" value="${jdbc.username}" />

                  <property name="password" value="${jdbc.password}" />

         </bean>

         <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

                  <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>

                  <property name="dataSource" ref="dataSource" />

                  <!-- 自动扫描mapping.xml文件 -->

                  <property name="mapperLocations" value="classpath:com /publicmapper/*.xml"></property>

         </bean>

         <!-- DAO接口所在包名,Spring会自动查找其下的类 -->

         <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

                  <property name="basePackage" value="com.publicdao." />

               <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>

         </bean>

         <!-- 事务管理 -->

         <bean id="transactionManager"

                  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

                  <property name="dataSource" ref="dataSource" />

         </bean>

</beans>

< config.properties >文件

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://<IP>/<dataBase>?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true

jdbc.username=

jdbc.password=

 

原文地址:https://www.cnblogs.com/chxwkx/p/11133147.html