2 wang18321810656 wang18321810656 于 2015.05.26 19:44 提问

spring+struts+hibernate整合问题,请大神帮忙!

求大神解答,兄弟初学ssh,今天整合他们三个。报错很多,但是最后竟然可以正确运行(我只实现了一个从数据库读用户名密码来登陆的功能。)
报错如下:(其中第一个错误就是Could not open ServletContext resource [/WEB-INF/applicationContext.xml],我在这个目录下有这个文件的。
而且我的web.xml里有这些内容。

contextConfigLocation
/WEB-INF/daoContext.xml,/WEB-INF/applicationContext.xml

<!-- 使用ContextLoaderListener初始化Spring容器 -->

org.springframework.web.context.ContextLoaderListener



INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
五月 26, 2015 7:36:43 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

6个回答

wang18321810656
wang18321810656   2015.05.26 19:45
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4772)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1683)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 25 more

五月 26, 2015 7:36:43 下午 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4772)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1683)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 25 more

五月 26, 2015 7:36:43 下午 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
五月 26, 2015 7:36:43 下午 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/SpringLearn] startup failed due to previous errors
五月 26, 2015 7:36:43 下午 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
五月 26, 2015 7:36:43 下午 org.springframework.web.context.support.XmlWebApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Tue May 26 19:36:43 CST 2015]; root of context hierarchy
五月 26, 2015 7:36:43 下午 org.springframework.web.context.support.XmlWebApplicationContext doClose
WARNING: Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Tue May 26 19:36:43 CST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:346)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:880)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4813)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5413)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1683)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

五月 26, 2015 7:36:43 下午 org.springframework.web.context.support.XmlWebApplicationContext doClose
WARNING: Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Tue May 26 19:36:43 CST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:359)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:888)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4813)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5413)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1683)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

五月 26, 2015 7:36:43 下午 org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:921)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4813)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5413)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1683)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

五月 26, 2015 7:36:43 下午 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor E:\J2eeLearning.metadata.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\SpringLearn.xml has finished in 3,708 ms
五月 26, 2015 7:36:43 下午 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor E:\J2eeLearning.metadata.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\Struts2Demo.xml
五月 26, 2015 7:36:43 下午 org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts2Demo' did not find a matching property.
五月 26, 2015 7:36:46 下午 org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
五月 26, 2015 7:36:46 下午 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
五月 26, 2015 7:36:46 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
五月 26, 2015 7:36:46 下午 org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue May 26 19:36:46 CST 2015]; root of context hierarchy
五月 26, 2015 7:36:46 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/daoContext.xml]
五月 26, 2015 7:36:46 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
五月 26, 2015 7:36:47 下午 com.mchange.v2.log.MLog
INFO: MLog clients using java 1.4+ standard logging.
五月 26, 2015 7:36:47 下午 com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
五月 26, 2015 7:36:48 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
五月 26, 2015 7:36:48 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
五月 26, 2015 7:36:48 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
五月 26, 2015 7:36:48 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
五月 26, 2015 7:36:48 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: 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 -> z8kflt9913yhcxm2qmuxq|3c39775b, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9913yhcxm2qmuxq|3c39775b, idleConnectionTestPeriod -> 0, initialPoolSize -> 2, jdbcUrl -> jdbc:mysql://localhost:3306/crsystem, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 20, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 200, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 2, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
五月 26, 2015 7:36:49 下午 org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
五月 26, 2015 7:36:49 下午 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
五月 26, 2015 7:36:49 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
五月 26, 2015 7:36:49 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: crsystem.cr_inf
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [manipular_name, cr_id, assign_name, description, cri, state]
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: []
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [primary]
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: crsystem.employee_inf
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [ismanager, password, user_name, emp_id]
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: []
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [primary]
五月 26, 2015 7:36:50 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
五月 26, 2015 7:36:50 下午 org.springframework.orm.hibernate4.HibernateTransactionManager afterPropertiesSet
INFO: Using DataSource [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 -> z8kflt9913yhcxm2qmuxq|3c39775b, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9913yhcxm2qmuxq|3c39775b, idleConnectionTestPeriod -> 0, initialPoolSize -> 2, jdbcUrl -> jdbc:mysql://localhost:3306/crsystem, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 20, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 200, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 2, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]] of Hibernate SessionFactory for HibernateTransactionManager
五月 26, 2015 7:36:51 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 4695 ms
五月 26, 2015 7:36:51 下午 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider info
INFO: Parsing configuration file [struts-default.xml]
五月 26, 2015 7:36:51 下午 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider info
INFO: Parsing configuration file [struts-plugin.xml]
五月 26, 2015 7:36:51 下午 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider info
INFO: Parsing configuration file [struts.xml]
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (spring) for (com.opensymphony.xwork2.ObjectFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ActionFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ResultFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ConverterFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.factory.InterceptorFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.factory.ValidatorFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.FileManagerFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.CollectionConverter)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.ArrayConverter)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.DateConverter)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.NumberConverter)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.StringConverter)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionFileProcessor)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterCreator)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterHolder)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.LocaleProvider)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.AbstractBeanSelectionProvider info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.TextParser)
五月 26, 2015 7:36:51 下午 org.apache.struts2.config.DefaultBeanSelectionProvider info
INFO: Loading global messages from [resource]
五月 26, 2015 7:36:51 下午 org.apache.struts2.spring.StrutsSpringObjectFactory info
INFO: Initializing Struts-Spring integration...
五月 26, 2015 7:36:51 下午 com.opensymphony.xwork2.spring.SpringObjectFactory info
INFO: Setting autowire strategy to name
五月 26, 2015 7:36:51 下午 org.apache.struts2.spring.StrutsSpringObjectFactory info
INFO: ... initialized Struts-Spring integration successfully
五月 26, 2015 7:36:52 下午 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor E:\J2eeLearning.metadata.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\Struts2Demo.xml has finished in 8,804 ms
五月 26, 2015 7:36:52 下午 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
五月 26, 2015 7:36:52 下午 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
五月 26, 2015 7:36:52 下午 org.apache.catalina.startup.Catalina start
INFO: Server startup in 13201 ms

wang18321810656
wang18321810656   2015.05.26 19:45

后面补齐控制台全部的输出。。。。有点长。。。。

diaoliwei2
diaoliwei2   Rxr 2015.05.26 20:08

看这句, java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]貌似还是applicationContext.xml这个文件找不到。其他一些错看起来也是报的springframework,也应该是spring的问题

dw_java08
dw_java08   2015.05.26 21:37

以后不要贴这么长的错误信息,贴出关键错误点就行了,你这一堆信息里面就把这句贴出来就行了,Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml] 找不到这个文件 建议把applicationContext.xml放在src目录下面,然后在你的web.xml中加上这部分<!--Spring的ApplicationContext 载入 -->

contextConfigLocation

classpath*:applicationContext.xml



org.springframework.web.context.ContextLoaderListener

就可以找到你的applicationContext.xml

wang18321810656
wang18321810656 恩恩,下次我会注意的,确实贴的错误太多了。。。。。⊙﹏⊙b汗
2 年多之前 回复
qq_27361099
qq_27361099   2015.05.26 22:33

基本概念和是使用实例

一:基本概念

 框架技术:框架是一个提供了可重用的公共结构的半成品,他保证了我们程序结构风格的统一。

 1.struts框架:是MVC设计模式的最经典的实例,它定义了通用的Controller(控制器),通过配置文件(一般是struts-        config.xml)隔离了Model(模型)和 view(视图),以Action的概念对用户的请求进行了封装,是代码更清晰易读还提

    供了自动将请求数据填充到对象以及页面标签简化了编码。

 2.hibernate框架:hibernate是一个优秀的持久化框架,负责简化将对象数据保存的数据库或从数据库中读取数据并封装

    到对象的工作,同过简单的配置和编码就可以替代JDBC复杂的编码程序,hibernate处理数据库操作的方式代表了当前

    的趋势。

 3.spring框架:是现有的javaEE技术更易用和促进良好的编程习惯,它是一个轻量级的框架,渗透了javaEE技术的方方面

    面。主要作为依赖注入容器和AOP实现存在。还提供了声明式事务,对DAO层的支持等简化开发的功能。

    SSH集成框架指的就是struts+spring+hibernate的技术框架。使用这个集成框架使我们的应用程序更加健壮,稳固,轻巧

    和优雅。

二:使用实例

   所需包:        

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

以上是本实例所需的所有jar包,下载解压后分别存放在lib文件夹下。下面是插图

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

 所有准备工作做完后开始准备编码:

 在webroot目录下新建 index.jsp

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

  现在我们需要创建实体类:在src下面新建包entity 在包下新创建类  UserInfo 如下:

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

在src包下分别创建action  和 actionForm   在action包下创建LoginAction.java

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

其中注解@Service("/login") 移交spring管理,"/login" 访问此action的路径

@Resource向action 注入loginService 属性

那么现在我们的index.jsp中的内容怎么和Loging匹配呢?我们看到saveInfo方法里有一个ActionForm属性,那么我们就要建立一ActionForm bean 继承ActionForm

在actionForm包下新建UserInfoForm.java

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客
下面 我们需要在WEB-INF下面新建struts-config.xml把我们的Action和ActionForm关联起来,建立映射关系。

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客
中定义了我们的表单类,也就是我们的ActiongFrom类,type为我们类的path

中定义了我们的Action 其中path中定义的"/login"就是我们在定义LogingAction中提到的@service("/login")这两个必须是一致的。如果我们通过注解交于spring管理,那么type中的值我们可以略去。parameter的值就是在我们请求action时所需要的参数的name,如我们请求访问ActiongFrom下面的save(),那么我们就要通过/login.do?method=save 访问.跳转标签呢指定我们在访问结束后更具我们定义的逻辑路径success 跳转到我们指定的物理路径success.jsp.

到这里细心的人士就会发现了,我们如何让struts和spring知道对方的存在呢,他们如何沟通?spring又是如何将控制权交给我们定义的LoginAction中呢?我们先来解决第一个问题,web.xml是tomcat这些应用服务管理的,因此我们将在这里把struts和spring关联起来。下面是web.xml将spring和struts关联的所有内容。

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客
spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

下面呢我们需要配置spring 默认路径为WEB-INF/applicationContext.xml

在这里 我们需要配置DataSource SessionFactory以及事务

spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客
spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

最后一次建立数据访问层BaseDao(interface) BaseDaoImpl(实现BaseDao接口) 以及业务逻辑层LoginService(interface) LoginServiceImpl(建议大家使用接口方便项目的扩展以及注入)
spring+struts+hibernate 整合 - 小鸡,快跑.. - btqnyao的博客

BaseDao.java
package dao;
public interface BaseDao{
public void save(T t);
}
BaseDaoImpl.java
package dao;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Service;
import util.GenericUtils;
@Service //移交spring管理
public class BaseDaoImpl extends HibernateDaoSupport implements BaseDao{
protected Class clazz = GenericUtils.getGenericClass(this.getClass());

@Resource
public void setSessionFactoryxxx(SessionFactory sessionFactory){
super.setSessionFactory(sessionFactory);
}
public void save(T objecT) {
// TODO Auto-generated method stubt
System.out.println("saved........");
getHibernateTemplate().save(objecT);
}
}

LoginService.java
package service;
import dao.BaseDao;
import entity.UserInfo;

public interface LoginService extends BaseDao {

}
LoginServiceImpl.java
package service;

import org.springframework.stereotype.Service;

import dao.BaseDaoImpl;
import entity.UserInfo;

@Service("loginService")
public class LogenServiceImp extends BaseDaoImpl implements LoginService{

}

基本流程到此也就结束了,大家可以试着写玩运行下。本例子只是为了清晰方便,有很多不足之处还望大家见谅。

wang18321810656
wang18321810656   2015.05.27 09:05

十分感谢大家的解答,我最后发现好像是tomcat服务器里有2个项目,然后我把那个没用的删除掉,就不报这些错误了。。。我也不知道为什么。。。迷迷糊糊啊。。。

Csdn user default icon
上传中...
上传图片
插入图片