`
keny_keny
  • 浏览: 10169 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

struts2.3+spring3.1.2+hibernate4.1.6 配置说明

阅读更多

lib包struts2.3+spring3.1.2+hibernate4.1.6 配置说明

auther :keny

date:2012/9/13

1.      包下载

l  hibernate-release-4.1.6.Final.zip

http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-3.1.2.RELEASE.zip

l  spring-framework-3.1.2.RELEASE

http://labs.mop.com/apache-mirror//struts/binaries/struts-2.3.4.1-all.zip

l  struts-2.3.4.1-all

http://labs.mop.com/apache-mirror//struts/binaries/struts-2.3.4.1-all.zip

2.      基本方法是合并lib包,里面有些是同样的包名,保留按照高版本的lib

       lib包

 

3.      整个工程采用的db2的数据库,已经有报表的功能。所以lib相对比较多。

 想必还有一些包可以删除,但时间比较赶,没有在进行删除包动作。

 

4.      hibernate4.1.6没有HibernateTemplate,以及HibernateCallback,以及常用的HibernateDaoSupport的类,需要做相应替换工作。

我采用的是所有的HibernateTemplate的用sessionFactory.getCurrentSession()替换掉,每个Dao都建立一个

         private SessionFactory sessionFactory;

         public SessionFactory getSessionFactory() {

                           return sessionFactory;

                       }

            public void setSessionFactory(SessionFactory sessionFactory) {

                           this.sessionFactory = sessionFactory;

                       }

这样在配置文件中声明下就把这个注入过来。

 

还有hibernate3有个execute的方法,这个在4中也取消了,我将这个方法全部改造到Query中。好在HQl功能强大,改造倒不是难事。

 

5.      Web.xml基本还是采用原先的spring3.0+hibernate3+strutus2的配置模式,只是在web.xml中按照hibernate4的包相应修改了一下。

如下:

<!-配置struts-->

  <filter>

    <filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

  </filter>

 

<!—配置spring的用到hibernate4-->

<filter>

    <filter-name>OpenSessionInViewFilter</filter-name>

    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>

          <!-启动是就初始化一个sessionFactory -->

          <init-param>

             <param-name>sessionFactoryBeanName</param-name>

             <param-value>sessionFactory</param-value>

         </init-param>

    

    <init-param>

      <param-name>singleSession</param-name>

      <param-value>true</param-value>

    </init-param>

    <init-param>

             <param-name>flushMode</param-name>

             <param-value>ALWAYS</param-value>

    </init-param>

 

  </filter>

  <filter-mapping>

    <filter-name>OpenSessionInViewFilter</filter-name>

    <url-pattern>/*</url-pattern>

  </filter-mapping>

  <filter-mapping>

    <filter-name>struts2</filter-name>

    <url-pattern>*.action</url-pattern>

    <url-pattern>*.jsp</url-pattern>

    <url-pattern>*.js</url-pattern>

  </filter-mapping>

<listener>

         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

     </listener>

     <listener>

         <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

     </listener>

     <listener>

         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

     </listener>

     <listener>

         <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>

     </listener>

6.      applicationContext.xml中。需要配置

说明sesionFactorybean的引入到哪里。

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

以及

         <!-- The following spring provided bean is used to do transaction manager -->

         <bean id="TransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">

                   <property name="sessionFactory">

                            <ref bean="sessionFactory" />

                   </property>

         </bean>

 

7.2012.9.13又发现了一个问题。重新启动的时候找这个包java.lang.ClassNotFoundException: org.apache.struts2.views.gxp.inject.InjectedObjectContainer,这个包是strutsgxp。相应的拷贝进去,结构重新启动,一直报这个包找不到,后解压该包,里面根本就没有inject目录啊。也不知道是哪个版本要这个,干脆采用减肥版本。发现原先的125jar包,真的有点多,做了一个瘦身lib ,删除-》编译-》删除,现在为87lib文件

 

8.新的xwork-core-2.3.4.1 以及去掉org.apache.commons.lang.work.StringUtils这个方法,调用原先的xwork版本的这个方法可以修改到commons-lang的中的org.apache.commons.lang.StringUtils方法中。

 

相关日志文件:

 

13:46:09,639  INFO  com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1bqrg9m8p1grhfc71tns05k|1f111ba, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.ibm.db2.jcc.DB2Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1bqrg9m8p1grhfc71tns05k|1f111ba, idleConnectionTestPeriod -> 30, initialPoolSize -> 5, jdbcUrl -> jdbc:db2://127.0.0.1:50000/GFYH, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 30, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 500, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]

13:46:12,652  INFO  com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:42 - Parsing configuration file [struts-default.xml]

13:46:12,811  INFO  com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:42 - Parsing configuration file [struts-plugin.xml]

13:46:12,857  INFO  com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:42 - Parsing configuration file [struts.xml]

13:46:12,863  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (spring) for (com.opensymphony.xwork2.ObjectFactory)

13:46:12,863  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.FileManager)

13:46:12,864  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)

13:46:12,864  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)

13:46:12,864  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)

13:46:12,866  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)

13:46:12,867  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)

13:46:12,869  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)

13:46:12,869  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)

13:46:12,877  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)

13:46:12,877  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)

13:46:12,877  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)

13:46:12,878  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)

13:46:12,881  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)

13:46:12,882  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)

13:46:12,882  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)

13:46:12,883  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)

13:46:12,887  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)

13:46:12,924  INFO  org.apache.struts2.spring.StrutsSpringObjectFactory:42 - Initializing Struts-Spring integration...

13:46:12,925  INFO  com.opensymphony.xwork2.spring.SpringObjectFactory:42 - Setting autowire strategy to autodetect

13:46:12,926  INFO  org.apache.struts2.spring.StrutsSpringObjectFactory:42 - ... initialized Struts-Spring integration successfully

13:46:14,024  INFO  com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:42 - Parsing configuration file [struts-default.xml]

13:46:14,041  INFO  com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:42 - Parsing configuration file [struts-plugin.xml]

13:46:14,047  INFO  com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:42 - Parsing configuration file [struts.xml]

13:46:14,049  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (spring) for (com.opensymphony.xwork2.ObjectFactory)

13:46:14,049  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.FileManager)

13:46:14,050  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)

13:46:14,050  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)

13:46:14,051  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)

13:46:14,051  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)

13:46:14,052  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)

13:46:14,052  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)

13:46:14,053  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)

13:46:14,059  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)

13:46:14,060  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)

13:46:14,060  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)

13:46:14,060  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)

13:46:14,060  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)

13:46:14,060  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)

13:46:14,061  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)

13:46:14,061  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)

13:46:14,061  INFO  org.apache.struts2.config.BeanSelectionProvider:42 - Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)

13:46:14,063  INFO  org.apache.struts2.spring.StrutsSpringObjectFactory:42 - Initializing Struts-Spring integration...

13:46:14,063  INFO  com.opensymphony.xwork2.spring.SpringObjectFactory:42 - Setting autowire strategy to autodetect

13:46:14,064  INFO  org.apache.struts2.spring.StrutsSpringObjectFactory:42 - ... initialized Struts-Spring integration successfully

 

启动的时候,日志文件比原先的多。希望有好的表现

 

参考文档,网上下载《Struts2Hibernate3Spring的简单配置与使用.pdf

这里就做下记录保存。

 

 

 

l

  • 大小: 67.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics