Environment: Struts2.3.4.1+spring3.1.1+hibernate3.6.10+mysql 5.5
Early configuration is not a big problem, in addition to a few jar package introduced when the situation, now put the required jar package screenshot, most of the SSH frame downloaded, there is no separate download it
Complete the integration, configure SSH, the main configuration files are as follows:
Xml:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version= " 3.0 "> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</ Welcome-file> </welcome-file-list> <!--struts2 configuration information--> <filter> <filter-name>struts2< /filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</ filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <
Url-pattern>*.action</url-pattern> </filter-mapping> <!--spring configuration information--> <context-param> <param-name>contextConfigLocation</param-name> <PARAM-VALUE>CLASSPath:applicationcontext.xml</param-value> </context-param> <listener> <listener-class> Org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!--log4j configuration information- -> <listener> <listener-class>org.springframework.web.util.log4jconfiglistener</listener-class > </listener> <context-param> <param-name>log4jConfigLocation</param-name> < Param-value>classpath:log.properties</param-value> </context-param> </web-app>
Struts:
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE struts public
"-//apache Software foundation//dtd struts Configuration 2.1//en"
"http:// Struts.apache.org/dtds/struts-2.1.dtd ">
<struts>
<package name=" test "extends=" Struts-default ">
<action name=" user_* "class=" userinfoaction "method=" {1} ">
<result name=" list ">/pages/userInfoList.jsp</result>
</action>
</package>
</struts>
Spring:
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:aop= " Http://www.springframework.org/schema/aop "xmlns:context=" Http://www.springframework.org/schema/context "xmlns: Jee= "Http://www.springframework.org/schema/jee" xmlns:tx= "Http://www.springframework.org/schema/tx" xsi: schemalocation= "Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/ Spring-aop-2.5.xsd 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/jee http://www.springframework.org/schema/jee/ Spring-jee-2.5.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ spring-tx-2.5.xSD "default-autowire=" AutoDetect "><!--error point--> <bean id=" DataSource "class=" Org.apache.commons.dbcp.BasicDataSource "destroy-method=" Close "> <property name=" driverclassname "value=" Com.mysql.jdbc.Driver "> </property> <property name=" url "value=" ${jdbc.url} "/> <property name=" us Ername "value=" ${jdbc.username} "/> <property name=" password "value=" ${jdbc.password} "/> <!--initialization connection--&G
T <property name= "InitialSize" value= "${jdbc.initialsize}"/> <property name= "maxactive" value= jdbc.maxactive} "/> <property name=" Maxidle "value=" ${jdbc.maxidle} "/> <property name=" MinIdle "value=" ${ Jdbc.minidle} "/> <!--whether to print a timeout error for a connection when the timeout connection is automatically recycled--> <property name=" logabandoned "value=" ${jdbc.logabandon " ed} "/> <!--whether to automatically recycle timeout connection--> <property name=" removeabandoned "value=" ${jdbc.removeabandoned "/> ;! --Timeout time (in s)--> <property name= "Removeabandonedtimeout" ValuE= "${jdbc.removeabandonedtimeout}"/> <property name= "maxwait" value= "${jdbc.maxwait}"/> </bean> & Lt;bean id= "Propertyconfigurer" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name= "Location" > <value>classpath:database.properties</value> </property> & lt;/bean> <bean id= "sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" scope = "Singleton" > <property name= "dataSource" ref= "DataSource" > </property> <property name= "Mappingloc"
Ations "> <list> <value> classpath:/com/mytest/dto/*.hbm.xml </value> </list> </property> <property name= "hibernateproperties" > <props> <prop key= "Jdbc.batch_size" > 20</prop> <prop key= "Hibernate.dialect" > Org.hibernate.dialect.MySQL5Dialect </prop> & Lt;prop key= "Hibernate.show_sql" >false</prop> </props> </property> </bean> <!--add Transaction control--> <!--define the transaction manager (declarative transaction)--&
Gt <bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" > < Property Name= "Sessionfactory" ref= "sessionfactory"/> </bean> <tx:advice id= "Txadvice" > <tx:attrib utes> <tx:method name= "insert*" propagation= "REQUIRED"/> <tx:method name= "update*" propagation= "REQUIRE" D "/> <tx:method name=" find* "propagation=" REQUIRED "read-only=" true "/> </tx:attributes> </tx:adv ice> <context:annotation-config/> <aop:config proxy-target-class= "true" > <aop:advisor pointcut= "E
Xecution (* com.mytest.service.*service.* (..)) " advice-ref= "Txadvice"/> </aop:config> <!--user Information management--> <bean id= "Userinfoaction" class= Ction. Userinfoaction "scope=" prototype "> <property name=" userinfoservice "ref=" UserInfoService "></property> </bean> <bean id=" Userinfoservice "class=" Com.mytest.service.impl.UserInfoServiceImpl "> <property name=" Userinfodao "ref=" Userinfodao "></" property> </bean> <bean id= "Userinfodao" class= "Com.mytest.dao.impl.UserInfoDaoImpl" > <property na Me= "Sessionfactory" ref= "sessionfactory" ></property> </bean> </beans>
Hibernate:
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE hibernate-configuration public
"-//hibernate/hibernate configuration DTD 3.0//en"
"http:// Hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">
Then start, report the exception as follows:
Serious: Exception sending context initialized event to listener instance of class Org.springframework.web.context.ContextLoad Erlistener Org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating Bean with Name ' Sessionfactory ' defined in class path resource [Applicationcontext.xml]: Unsatisfied dependency expressed through Bean Pro Perty ' eventlisteners ':: Error creating Bean with Name ' TransactionManager ' defined in class path resource [Applicationco Ntext.xml]: Cannot resolve reference to bean ' sessionfactory ' while the setting bean property ' sessionfactory '; Nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:Error creating beans with Name ' Sessionfactory ': Factorybean which is currently in creation returned null from GetObject; Nested exception is org.springframework.beans.factory.BeanCreationException:Error creating beans with Name ' TransactionManager ' defined in class path resource [Applicationcontext.xml]: Cannot resolveTo the bean ' sessionfactory ' while the setting bean property ' sessionfactory '; Nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:Error creating beans with Name ' Sessionfactory ': Factorybean which is currently in creation returned null from GetObject at ORG.SPRINGFRAMEWORK.BEANS.FAC Tory.support.AbstractAutowireCapableBeanFactory.autowireByType (abstractautowirecapablebeanfactory.java:1199) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1091) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:517) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean ( abstractautowirecapablebeanfactory.java:456) at org.springframework.beans.factory.support.abstractbeanfactory$1. GetObject (abstractbeanfactory.java:294) at Org.springframework.beans.factory.support.DefaultSiNgletonbeanregistry.getsingleton (defaultsingletonbeanregistry.java:225) at Org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (abstractbeanfactory.java:291) at Org.springframework.beans.factory.support.AbstractBeanFactory.getBean (abstractbeanfactory.java:193) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons ( defaultlistablebeanfactory.java:567) at Org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization ( abstractapplicationcontext.java:913) at Org.springframework.context.support.AbstractApplicationContext.refresh ( abstractapplicationcontext.java:464) at
Org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext (contextloader.java:385) At Org.springframework.web.context.ContextLoader.initWebApplicationContext (contextloader.java:284) at Org.springframework.web.context.ContextLoaderListener.contextInitialized (contextloaderlistener.java:111) at Org.apaChe.catalina.core.StandardContext.listenerStart (standardcontext.java:4206) at Org.apache.catalina.core.StandardContext.start (standardcontext.java:4705) at Org.apache.catalina.core.ContainerBase.addChildInternal (containerbase.java:799) at Org.apache.catalina.core.ContainerBase.addChild (containerbase.java:779) at Org.apache.catalina.core.StandardHost.addChild (standardhost.java:601) ...
......
Baidu, Google a bunch, check a bunch of APIs, to the official website to see the framework version change Logs,demo ... And then finally found out why.
The Beans Bean assembly attribute default-autowire= "AutoDetect", originally a spring configuration, was configured to be automatic, so this exception was generated. It is then deleted and manually injected at each DAO layer instead.
Reboot, run, everything's fine.
The problem has been solved for the time being, but there are still questions, because it is necessary to configure the injection manually through the property properties in each of the DAO layer's beans, without knowing how default-autowire= "AutoDetect" can be configured to implement automatic injection.