[color=red][size=medium]将appDatasource.xml,appService.xml,jdbc.properties放入src/resource下
将annomvc-servlet.xml与web.xml放入WEB-INF下[/size][/color]
appDatasource.xml:
appService.xml:
jdbc.properties:
annomvc-servlet.xml:
web.xml:
将annomvc-servlet.xml与web.xml放入WEB-INF下[/size][/color]
appDatasource.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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean id="njl_dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="${jdbc.driverClass}"
p:jdbcUrl="${jdbc.url}"
p:user="${jdbc.username}"
p:password="${jdbc.password}"
p:maxPoolSize="${c3p0.maxPoolSize}"
p:minPoolSize="${c3p0.minPoolSize}"
p:initialPoolSize="${c3p0.initialPoolSize}"
p:checkoutTimeout="${c3p0.checkoutTimeout}"
p:maxStatements="${c3p0.maxStatements}"
p:idleConnectionTestPeriod="${c3p0.idleConnectionTestPeriod}"
p:acquireIncrement="${c3p0.acquireIncrement}"
p:maxIdleTime="${c3p0.maxIdleTime}"
p:numHelperThreads="${c3p0.numHelperThreads}"
/>
<bean id="sessionFactory_njl"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
parent="AbstractSessionFactory">
<property name="dataSource" ref="njl_dataSource" />
<property name="annotatedClasses">
<list>
<value>com.njl.web.entity.Users</value>
<value>com.njl.web.entity.Role</value>
<value>com.njl.web.entity.Competence</value>
<value>com.njl.web.entity.Role_Comp</value>
</list>
</property>
</bean>
<bean id="njl_baseDao" class="com.njl.web.common.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory_njl"/>
</bean>
<bean id="AbstractSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
abstract="true">
<property name="dataSource" ref="njl_dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</prop>
<prop key="hibernate.connection.release_mode">
auto
</prop>
<prop key="hibernate.jdbc.batch_size">
50
</prop>
<prop key="hibernate.jdbc.fetch_size">
100
</prop>
<prop key="hibernate.jdbc.use_scrollable_resultset">
true
</prop>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.hbm2ddl.auto">
${hibernate.hbm2ddl.auto}
</prop>
<prop key="hibernate.cache.use_query_cache">
${hibernate.cache.use_query_cache}
</prop>
<prop key="hibernate.cache.provider_class">
${hibernate.cache.provider_class}
</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory_njl" />
<property name="entityInterceptor" >
<bean id="daoInterceptor" class="com.njl.web.common.dao.DaoInterceptor"></bean>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
appService.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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:property-placeholder location="classpath:jdbc.properties" />
<import resource="appDatasource.xml"/>
<!-- 开启自动扫描action路径-->
<context:annotation-config />
<context:component-scan base-package="com.njl.web.*" />
<!-- aspectj -->
<aop:aspectj-autoproxy/>
<!-- 激活@requestMapping接口 -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
</beans>
jdbc.properties:
# driverClass
#jdbc.driverClass= com.p6spy.engine.spy.P6SpyDriver
jdbc.driverClass= com.mysql.jdbc.Driver
jdbc.dialect=org.hibernate.dialect.MySQLDialect
# Database URL
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
# Database login information
jdbc.username=root
jdbc.password=root
c3p0.maxPoolSize=50
c3p0.minPoolSize=5
c3p0.initialPoolSize=10
c3p0.checkoutTimeout=5000
c3p0.maxStatements=100
c3p0.idleConnectionTestPeriod=120
c3p0.acquireIncrement=10
c3p0.maxIdleTime=60
c3p0.numHelperThreads=6
# hibernate setings
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.use_query_cache=false
annomvc-servlet.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<context:component-scan base-package="com.njl.web"/>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>104857600</value>
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
</bean>
<!-- jsp view -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>testExtjs.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:appService.xml
</param-value>
</context-param>
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.localizationContext
</param-name>
<param-value>message</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<servlet-name>annomvc</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- <filter>
<filter-name>njlSecurityFilter</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>njlSecurityFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
-->
<servlet>
<servlet-name>annomvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>annomvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>annomvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
</web-app>