我正在尝试使用spring 4,hiberate 4开发一个rest应用程序并使用BeanDefinitionStoreException获取跟随错误。
我已经将类从hibernate3更改为hibernate4,尽管我遇到了异常
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected
从ServletContext资源解析XML文档的异常[/ WEB-INF / rest- servlet.xml中];嵌套异常是java.lang.NoClassDefFoundError: 组织/ springframework的/交易/拦截器/ TransactionInterceptor org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:413) org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335) org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303) org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216) org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187) org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:643) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:606) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:657) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:525) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:620) org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:316) java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(未知来源) java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源) org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(未知来源)
库文件
我的Dispatcher-servlet文件:
我已经通过一些帖子来解决org.xml.sax.SAXParseException, 我在bean中包含bean:bean甚至在xsi:schemaLocation
中提到 <?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-
beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-
context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-
4.0.xsd ">
<annotation-driven/>
<beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<beans:ref bean="jsonMessageConverter"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
</beans:bean>
<context:component-scan base-package="net.javaonline.spring.restful" />
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="org.postgresql.Driver" />
<beans:property name="url" value="jdbc:postgresql://localhost:5433/SCM1" />
<beans:property name="username" value="postgres" />
<beans:property name="password" value="postgres123"/>
</beans:bean>
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</beans:prop>
<beans:prop key="hibernate.validator.apply_to_ddl">false</beans:prop>
<beans:prop key="hibernate.validator.autoregister_listeners"> false</beans:prop>
<beans:prop key="hibernate.show_sql"> false </beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" >
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
</beans:beans>
<pre> Here following are the library files<pre>
lib/commons-collections-3.2.1.jar
lib/commons-logging-1.1.1.jar
lib/dom4j-1.6.1.jar
lib/hibernate-commons-annotations-4.0.1.Final.jar
lib/hibernate-core-4.0.1.Final.jar
lib/hibernate-jpa-2.0-api-1.0.1.Final.jar
lib/jackson-annotations-2.5.4.jar
lib/jackson-core-2.2.0.jar
lib/jackson-databind-2.1.4.jar
lib/javassist-3.15.0-GA.jar
lib/jboss-logging-3.1.0.CR2.jar
lib/jboss-transaction-api_1.1_spec-1.0.0.Final.jar
lib/jstl-1.2.jar
lib/spring-aop-4.0.0.RELEASE.jar
lib/spring-aspects-4.0.0.RELEASE.jar
lib/spring-beans-4.0.0.RELEASE.jar
lib/spring-context-4.0.0.RELEASE.jar
lib/spring-core-4.0.0.RELEASE.jar
lib/spring-expression-4.0.0.RELEASE.jar
lib/spring-framework-bom-4.0.0.RELEASE.jar
lib/spring-jdbc-2.0.6.jar
spring-orm-4.0.0.RELEASE.jar
lib/spring-tx-4.0.0.RELEASE.jar
lib/spring-web-4.0.0.RELEASE.jar
lib/spring-webmvc-4.0.0.RELEASE.jar
答案 0 :(得分:0)
您正在使用Hibernate 4但是在创建bean时,您正在尝试使用hibernate3类。
在xml配置中,将任何引用从hibernate3更改为hibernate4。例如,在创建工厂和事务管理器时。
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate4.annotation.
AnnotationSessionFactoryBean">
....
</beans:bean>
<beans:bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate4.
HibernateTransactionManager" >
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
向libray aopalliance.jar
添加依赖项<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>