问题描述
今天自己弄了一下s2sh整合,抛出了异常! 这是applicationContext.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee" 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/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 http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd " default-autowire="byType"> <context:annotation-config /> <context:component-scan base-package="*" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"> </property> <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"> </property> <property name="username" value="liuwei"></property> <property name="password" value="liuwei"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" destroy-method="close"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> <prop key="hibernate.show_sql"> true</prop> </props> </property> </bean></beans> 这是web.xml<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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>/*</url-pattern> </filter-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener></web-app> 这是包 问题补充:这个是错误信息<br /><br />严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener<br />org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDaoImpl' defined in file [E:Tomcat 6.0webappsliuweisshWEB-INFclassesliuweidaoimplUserDaoImpl.class]: Unsatisfied dependency expressed through bean property 'sessionFactory': : Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Cannot cache an unknown entity: java.runtime.name; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Cannot cache an unknown entity: java.runtime.name<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1150)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1040)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)<br />at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)<br />at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)<br />at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)<br />at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)<br />at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)<br />at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)<br />at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)<br />at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)<br />at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)<br />at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)<br />at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)<br />at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)<br />at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)<br />at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)<br />at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)<br />at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)<br />at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)<br />at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)<br />at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)<br />at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)<br />at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)<br />at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)<br />at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)<br />at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)<br />at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)<br />at org.apache.catalina.core.StandardService.start(StandardService.java:516)<br />at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)<br />at org.apache.catalina.startup.Catalina.start(Catalina.java:566)<br />at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br />at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br />at java.lang.reflect.Method.invoke(Method.java:597)<br />at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)<br />at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)<br />Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Cannot cache an unknown entity: java.runtime.name<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1403)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)<br />at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)<br />at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)<br />at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)<br />at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)<br />at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:825)<br />at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:767)<br />at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:685)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1134)<br />... 37 more<br />Caused by: org.hibernate.MappingException: Cannot cache an unknown entity: java.runtime.name<br />at org.hibernate.cfg.Configuration.setCacheConcurrencyStrategy(Configuration.java:2065)<br />at org.hibernate.cfg.Configuration.setCacheConcurrencyStrategy(Configuration.java:2058)<br />at org.hibernate.cfg.Configuration.setCacheConcurrencyStrategy(Configuration.java:2052)<br />at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:729)<br />at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)<br />at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)<br />... 47 more<br />2011-9-15 9:41:09 org.apache.catalina.core.StandardContext start<br />严重: Error listenerStart<br />2011-9-15 9:41:09 org.apache.catalina.core.StandardContext start<br />严重: Context [/liuweissh] startup failed due to previous errors<br /><br /><br /><br />
解决方案
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingLocations"> <list> <value>classpath:/hibernate_mappings/*</value> </list> </property> <property name="hibernateProperties"> <props> <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.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop> </props> </property> </bean>你的持久化实体配置文件地址都没有配置
解决方案二:
...错误信息全部贴出来。