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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--<context:annotation-config/>-->
<context:component-scan base-package="com.note.service"/>
<!--想所有返回的date格式固定,但是没用-->
<mvc:annotation-driven/>
<!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">-->
<!--<property name="messageConverters">-->
<!--<list>-->
<!--<bean class="org.springframework.http.converter.StringHttpMessageConverter">-->
<!--<property name="supportedMediaTypes">-->
<!--<list>-->
<!--<value>-->
<!--text/html;charset=UTF-8-->
<!--</value>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--<!– 启动JSON格式的配置 –>-->
<!--<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">-->
<!--<!– 解决 HttpMediaTypeNotAcceptableException: Could not find acceptable representation –>-->
<!--<property name="supportedMediaTypes">-->
<!--<list>-->
<!--<value>application/json;charset=UTF-8</value>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!-- 数据源配置文件 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:init.properties</value>
</property>
</bean>
<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${datasource.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${datasource.url}</value>
</property>
<property name="user">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
<property name="acquireIncrement">
<value>${c3p0.acquireIncrement}</value>
</property>
<property name="initialPoolSize">
<value>${c3p0.initialPoolSize}</value>
</property>
<property name="minPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<property name="maxPoolSize">
<value>${c3p0.maxPoolSize}</value>
</property>
<property name="maxIdleTime">
<value>${c3p0.maxIdleTime}</value>
</property>
<property name="idleConnectionTestPeriod">
<value>${c3p0.idleConnectionTestPeriod}</value>
</property>
<property name="maxStatements">
<value>${c3p0.maxStatements}</value>
</property>
<property name="numHelperThreads">
<value>${c3p0.numHelperThreads}</value>
</property>
</bean>
<!-- 配置p6spy -->
<bean id="myP6DataSource" class="com.p6spy.engine.spy.P6DataSource">
<constructor-arg ref="dataSource">
</constructor-arg>
</bean>
<!-- hibernate sessionFactory 配置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myP6DataSource"/>
<!-- 模型扫描 -->
<property name="packagesToScan">
<list>
<value>com.note.service</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.jdbc.fetch_size">
${hibernate.jdbc.fetch_size}
</prop>
<prop key="hibernate.jdbc.batch_size">
${hibernate.jdbc.batch_size}
</prop>
<prop key="hibernate.default_schema">
${datasource.schema}
</prop>
<prop key="hibernate.hbm2ddl.auto">
${hibernate.hbm2dd2.auto}
</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">
${hibernate.bytecode.use_reflection_optimizer}
</prop>
<prop key="hibernate.check_nullability">
${hibernate.check_nullability}
</prop>
<prop key="hibernate.search.autoregister_listeners">
${hibernate.search.autoregister_listeners}
</prop>
<prop key="hibernate.connection.autocommit">
${hibernate.connection.autocommit}
</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/note_service?autoReconnect=true</prop>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
</props>
</property>
</bean>
<!-- 开启AOP监听 只对当前配置文件有效 -->
<aop:aspectj-autoproxy expose-proxy="true"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<!-- 指定所上传文件的总大小,单位字节。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
<property name="maxUploadSize" value="11240000"/>
</bean>
<!-- 开启注解事务 只对当前配置文件有效 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 事务 -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<aop:config>
<aop:pointcut id="txService" expression="execution(* com.note..service.*.*(..))"/>
<aop:advisor pointcut-ref="txService" advice-ref="txAdvice"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="bDelete*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="allow*" propagation="REQUIRED"/>
<tx:method name="query*" read-only="true"/>
</tx:attributes>
</tx:advice>
<mvc:interceptors>
<bean class="com.note.service.network.interceptor.UserVerifyInterceptor"/>
</mvc:interceptors>
<bean class="com.note.service.network.interceptor.UserVerifyInterceptor">
<property name="exceptUrls">
<set>
<value>/loginService/login</value>
<value>/loginService/verifyLoginName</value>
<value>/loginService/regist</value>
<value>/loginService/loginPrepare</value>
<value>/test/test</value>
<value>/test/jspTest</value>
<value>/webSocketServer</value>
<value>/updateService/getServiceVersion</value>
<value>/updateService/downloadLastVersion</value>
<value>/updateService/downloadLastVersionB</value>
<value>/loginService/retrievePsw</value>
<value>/loginService/forgetPsw</value>
<value>/loginService/retrievePswFinished</value>
<value>/updateService/downloadPage</value>
</set>
</property>
</bean>
<!--<!–Spring3.1 之后的自定义注解 HandlerAdapter –>-->
<!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">-->
<!--<property name="webBindingInitializer">-->
<!--<bean class="GlobalDateBinder" />-->
<!--</property>-->
<!--<property name="messageConverters">-->
<!--<list>-->
<!--<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />-->
<!--<bean class="org.springframework.http.converter.StringHttpMessageConverter">-->
<!--<property name="writeAcceptCharset" value="false" />-->
<!--<property name="supportedMediaTypes">-->
<!--<list>-->
<!--<value>text/plain;charset=UTF-8</value>-->
<!--<value>*/*;charset=UTF-8</value>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />-->
<!--<bean class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter" />-->
<!--<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
</beans>
init.properties:
datasource.type=mysql
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/note_service?autoReconnect=true
datasource.username=root
datasource.password=123456
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.jdbc.batch_size=25
hibernate.jdbc.fetch_size=50
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2dd2.auto=update
hibernate.current.session.context.class=thread
hibernate.bytecode.use_reflection_optimizer=false
hibernate.check_nullability=false
hibernate.search.autoregister_listeners=false
hibernate.connection.autocommit=true
datasource.schema=note_service
c3p0.acquireIncrement=2
c3p0.initialPoolSize=2
c3p0.idleConnectionTestPeriod=900
c3p0.minPoolSize=2
c3p0.maxPoolSize=10
c3p0.maxStatements=50
c3p0.numHelperThreads=10
c3p0.maxIdleTime=60
springMVC-servlet.xm放在webapp的WEB-INF目录下
<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- 指定自动扫描路径 -->
<!--<context:component-scan base-package="com.note.service"></context:component-scan>-->
<!--<context:component-scan base-package="com.note.service.*" >-->
<!--<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />-->
<!--</context:component-scan>-->
<!--<!–json转换器–>-->
<!--<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">-->
<!--<property name="supportedMediaTypes" value="application/json"/>-->
<!--</bean>-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>