Spring2.5.6+Hibernate3.4+Struts2 2.1.6 +JPA集成

来源:互联网 发布:图片标注软件 编辑:程序博客网 时间:2024/06/10 05:02

    总结下吧。

所需lib包列表:    

    配置文件写的倒是很简单,我又不想搞出太多的无用包导致最后系统加载很慢,最后综合了下就尽量少的导包吧。结果到最后都是jar包冲突,搞得我累死啊。简单说明下...后来发现还是有冲突的包和漏包的问题,这个碰到以后再说了

    antlr-2.7.6.jar    
    aspectjrt.ja(这个好像是springAop 注解支持的类)
    aspectjweaver.jar
    backport-util-concurrent-3.1.jar
    cglib-nodep-2.1_3.jar
    common-annotations.jar
    commons-collections-2.1.1.jar
    commons-dbcp.jar
    commons-fileupload-1.2.1.jar
    commons-io-1.3.2.jar
    commons-logging.jar(apache的日志类)
    commons-logging-1.1.1.jar

    commons-pool.jar(这个是对象池核心包,spring会用到)
    dom4j-1.6.1.jar(dom4j核心)
    ehcache-1.5.0.jar(缓存支持)
    ejb3-persistence.jar
    freemarker-2.3.13.jar
    hibernate3.jar(hibernate核心包)
    hibernate-annotations.jar(这两个是hibernate的注解支持包,个人现在喜欢上了hibernate的注解式配置,调试的时候很方便)
    hibernate-commons-annotations.jar
    javassist.jar
    jta.jar(jta支持)
    junit-4.4.jar(这个是junit-4.4的依赖包,我写单元测试用的)
    log4j-1.2.15.jar    
    ognl-2.6.11.jar
    ojdbc14.jar(oracle的Driver可以更换)
    slf4j-api-1.5.8.jar(这两个都是slf4j的依赖包,没有的话slf4j会运行异常)
    slf4j-log4j12-1.5.8.jar
    spring.jar(spring核心包)
    struts2-core-2.1.6.jar(struts2核心包)
    struts2-spring-plugin-2.1.6.jar(看这个样子像spring对struts2支持的时候需要)
    xwork-2.1.2.jar


Web.xml配置方案

 <!-- 加载spring的配置文件 --> <context-param>  <param-name>contextConfigLocation</param-name>  <param-value>   classpath*:spring-*.xml  </param-value> </context-param>  <!-- 编码过滤器元素 --> <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>  <url-pattern>/*</url-pattern> </filter-mapping>   <!-- 事件监听程序 --> <!--Spring的ApplicationContext 载入 --> <listener>  <listener-class>   org.springframework.web.context.ContextLoaderListener  </listener-class> </listener>  <!-- Spring 刷新Introspector防止内存泄露 --> <listener>  <listener-class>   org.springframework.web.util.IntrospectorCleanupListener  </listener-class> </listener>  <!-- struts2配置拦截器 --> <filter>  <filter-name>struts2Filter</filter-name>  <filter-class>   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  </filter-class> </filter>  <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 --> <filter-mapping>  <filter-name>struts2Filter</filter-name>  <url-pattern>*.action</url-pattern> </filter-mapping>  <filter-mapping>  <filter-name>struts2Filter</filter-name>  <url-pattern>*.jsp</url-pattern> </filter-mapping>  <session-config>  <session-timeout>600</session-timeout> </session-config>

Spring-base.xml的配置方案

    这个spring-base.xml我是放在src/config这个Source Folder里面的,打算以后的配置文件都放在这里,这样分门别类的 看着比较舒服。也好详细配置。

<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"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-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/jee http://www.springframework.org/schema/jee/spring-jee-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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"default-lazy-init="true"><description>Spring公共配置文件</description><!-- 声明可使用注解自动注入 -->    <context:annotation-config />         <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --><context:component-scan base-package="*" />        <!-- 定义受环境影响易变的变量 --><bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /><property name="ignoreResourceNotFound" value="true" /><property name="locations"><list><!-- jdbc配置 --><value>classpath*:jdbc.properties</value></list></property></bean><!-- 数据库连接的取得 --><bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource" ><property name="driverClassName" value="${jdbc.driverClassName}"/>    <property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /></bean><bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="namingStrategy"><bean class="org.hibernate.cfg.ImprovedNamingStrategy" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">${jdbc.hibernate.dialect}</prop><prop key="hibernate.show_sql">${jdbc.hibernate.show_sql}</prop><prop key="hibernate.cache.provider_class">${jdbc.hibernate.cache.provider_class}</prop>                <prop key="hibernate.cache.use_query_cache">${jdbc.hibernate.cache.use_query_cache}</prop><prop key="hibernate.cache.use_second_level_cache">${jdbc.hibernate.cache.use_second_level_cache}</prop><!-- 在hibernate初始化的时候进行数据库表结构的更新 --><!-- <prop key="hibernate.hbm2ddl.auto">${jdbc.hibernate.hbm2ddl.auto}</prop> --></props></property><property name="packagesToScan"><list><value>com.yohoph.*</value></list></property> </bean><!-- 事务管理器配置,单数据源事务 --><bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- 使用annotation定义事务 --><tx:annotation-driven transaction-manager="transactionManager" /><!-- HibernateTemplate支持 --><bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory"></property></bean><!-- JdbcTemplate支持 --><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean></beans>

附带还有个jdbc.properties

这个嘛就比较随意, 因为我这边还没考虑好数据库,所以这边的东西都还比较乱大致的看下吧

jdbc.driverClassName=sun.jdbc.odbc.JdbcOdbcDriverjdbc.url=jdbc\:odbc\:driver\={Microsoft Access Driver (*.mdb)};DBQ\=E\:\\website\\tomcat\\access.mdbjdbc.username=dbajdbc.password=sqljdbc.hibernate.dialect=org.hibernate.dialect.SQLServerDialectjdbc.hibernate.show_sql=truejdbc.hibernate.cache.provider_class=org.hibernate.cache.EhCacheProviderjdbc.hibernate.cache.use_query_cache=truejdbc.hibernate.cache.use_second_level_cache=truejdbc.hibernate.hbm2ddl.auto=update


剩下的就OK了,应该没事了。



原创粉丝点击