与AnnotationSessionFactoryBean问题

我用我的启动SessionFactory的配置如下:

<?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- Concrete services --> <bean id="userService" class="org.blog.service.UserService" parent="sessionService" /> <!-- Hibernate base --> <bean id="sessionService" abstract="true" class="org.blog.service.SessionService"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>org.blog.domain.User</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/website"/> <property name="username" value="root"/> <property name="password" value="enter"/> </bean> </beans>

但是,下面的错误弹出做运行时:

root cause org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in URL [jndi:/localhost/Blog/WEB-INF/services.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [jndi:/localhost/Blog/WEB-INF/services.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1299) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1061) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:543) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:730) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:387) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:447) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:342) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:308) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) javax.servlet.GenericServlet.init(GenericServlet.java:212) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) java.lang.Thread.run(Thread.java:613) root cause org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [jndi:/localhost/Blog/WEB-INF/services.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1395) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188) org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322) org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1299) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1061) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:543) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:730) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:387) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:447) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:342) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:308) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) javax.servlet.GenericServlet.init(GenericServlet.java:212) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) java.lang.Thread.run(Thread.java:613) root cause java.lang.NoClassDefFoundError sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) java.lang.reflect.Constructor.newInstance(Constructor.java:501) org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104) org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:771) org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:515) org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1454) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1392) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188) org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322) org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1299) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1061) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:543) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:730) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:387) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:447) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:342) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:308) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) javax.servlet.GenericServlet.init(GenericServlet.java:212) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) java.lang.Thread.run(Thread.java:613)

我觉得有什么不对我的库。

目前我使用这些:

  • 公共馆藏-3.1.jar
  • 公地dbcp.jar
  • 公共-logging.jar的
  • 公地pool.jar
  • dom4j的-1.6.1.jar
  • EJB3,persistence.jar中
  • hibernate3.jar里(3.5还包括注释)
  • javaee.jar
  • 了Javassist-3.9.0.GA.jar
  • 的jstl.jar JTA-1.1.jar
  • 使用mysql-connector-java的-3.1.12-bin.jar的
  • org.springframework.asm-3.​​0.0.RC1.jar
  • org.springframework.beans-3.0.0.RC1.jar
  • org.springframework.context-3.0.0.RC1.jar
  • org.springframework.context.support-3.0.0.RC1.jar
  • org.springframework.core-3.0.0.RC1.jar
  • org.springframework.expression-3.0.0.RC1.jar
  • org.springframework.jdbc-3.0.0.RC1.jar
  • org.springframework.orm-3.0.0.RC1.jar
  • org.springframework.transaction-3.0.0.RC1.jar
  • org.springframework.web-3.0.0.RC1.jar
  • org.springframework.web.servlet-3.0.0.RC1.jar
  • SLF4J-API-1.5.8.jar
  • standard.jar

谁能确定是什么原因导致我的错误? 我的源代码分发是http://code.google.com/p/jeesh-blog/

--------------解决方案-------------

你正在使用SLF4J,但只有具备SLF4J-API中的类路径, 还需要SLF4J的实现,如SLF4J-NOP或SLF4J-Simplelogger。

您可以通过一个简单的测试案例,它初始化Spring的ApplicationContext看到这一点, Java 6的运行它 ,看看哪些类不能被找到:

public class AppCtxTest {
@Test
public void testApplicationContext() throws Exception {
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
"app/WEB-INF/services.xml");
ctx.close();
}
}

输出将显示缺少什么;

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userService' defined in file [C:\Users\mhaller\workspace\Blog\app\WEB-INF\services.xml]:
Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';
nested exception is ...
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in file [C:\Users\mhaller\workspace\Blog\app\WEB-INF\services.xml]:
Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder

事实上,也有一些更多的依赖关系缺失:

  • SLFJ4j实施(SLF4J-xxx.jar)
  • Java持久性javax.persistence.ElementCollection

休眠的javax /持续性/ ElementCollection

* JPA 2.0被运往作为Java EE 6版本的一部分(Sept09)

* JPA 2.0参考实现将是项目的EclipseLink(开源TopLink的)集装箱装运,WLS,Glassfish,从春天或独立的http:/ www.eclipse.org/eclipselink

下载JPA 2.0提议最终草案,并看看的http:/ / www.jcp.org/ EN / JSR /详细ID = 317

分类:java的 时间:2012-01-01 人气:0
本文关键词: java的,春天,休眠
分享到:

相关文章

  • 这是java的春天Hibernate网站最好的Web服务器 2012-06-20

    我有VPS,我想用java春天休眠mysql的测试网站. 这是最好的Web服务器安装linux服务器上 --------------解决方案------------- 你并不需要一个Web服务器来测试 - Tomcat和Jetty的都有内置的HTTP服务器是完全足够了. 你不需要IIS或Apache Web服务器,但你需要安装一个servlet / JSP引擎和JVM. 如果安装了这是从servlet / JSP引擎单独的服务器上你的MySQL数据库你不说. 我建议你​​安排事情的方式. 春天T

  • 我如何信号在Java中的休眠线程? 2013-03-24

    我正在写一个网络类UDP客户端 - 服务器对,我已经打了问题. 这是一个相当非正统的网络分配,所以有点背景的第一: 的目标是创建一个服务器来实现基于推送的通知. 这里的关键点是服务器有联系的任何地址,这是最后一次见到客户端,以及侦听客户端的控制报文. 因此,因此,我必须在客户端上运行的周期性地发送UDP数据包到服务​​器,它记录了原点时,它需要发送一个响应线程. 这种技术还萧条通过NAT的,作为发送刷新地址转换. 于是,这里是我的困境:除非我弄错了,在NAT映射它自己的地址和生成的端口号到它的客

  • Java和春天后端用Ruby(Rhomobile的)前端安全 2014-04-04

    我目前正在建设使用Rhomobile的移动应用程序. 该应用程序将简单地调用了一堆的REST Web服务. 后端REST服务是用Java编写+春天. 我想知道的安全注意事项是什么. 我们的要求很简单,我们需要一种安全的方式为用户与应用程序登录,然后才能够调用Web服务. 有没有人有结婚这些技术的经验. 什么是我的选择. 此刻我在看你可以使用Spring Security或四郎,但只是想知道如果任何人有更好的体验. 正如一个音符,我们将使用JSON的所有通信. --------------解决方案

  • 教程在那里我可以开始掌握并全面掌握了Java的春天2.5 +休眠(W /一些其他框架) 2012-01-15

    我想完全掌握和全面掌握Java的Spring 2.5中和Hibernate框架的时间有限(可能在不到2天?),想问问这个社会,如果你能指出我在哪里可以掌握启动两个框架. 我有点明白,它需要时间来充分掌握两个框架,但它会​​好起来的,如果你能指出教程,其中的注释,XML映射,以及许多基本的东西,我需要掌握Spring和Hibernate的解释为初学者谁只尝试过去几天内明白了吗? 我试着谷歌上搜索一大堆的时间和浪费已经3天试图找出和理解的概念,但它似乎我明白了什么呢. 其中一个主要问题是,我只能使用

  • Java中,休眠,春天 2014-07-02

    我有2个单位用户和状态. 我可以加载的用户列表,可以看到控制台的SQL(日志) (选择this_.id为id0_0_,this_.cl_point_id为cl2_0_0_,this_.date_ll为date3_0_0_,this_.date_reg为date4_0_0_,this_.name为name0_0_,this_.passw_salt为passw6_0_0_,this_.status_id为status7_0_0_,this_.passw为passw0_0_, this_.login为

  • 我想用两个不同的表的id作为第三个表的ID(休眠,JAVA,春天) 2012-01-09

    我有表Owner和Species ,两个实体自动生成的ID整数列. 我有第三个表Cat ,我想是基于前两个表的ID的能力retireve,所以我想要做的事,如: Session session = sessionFactory.getCurrentSession(); Cat cat = (Cat) session.get(Cat.class, owner.getId, species.id); 代替 Cat cat = (Cat) session.get(Cat.class, id); 什么是

  • 获得空指针异常在Java春天休眠应用 2015-01-20

    我有类注册的用户名与密码的电子邮件 我有如下的道,服务类功能 public Registration get( Integer id ) { logger.debug("Getting person"); return registrationDAO.findUserByID(id); } @Resource(name="registrationService") private RegistrationService registrationService; pu

  • 春天休眠版本问题 2013-09-16

    我使用下列库: 休眠休眠核心3.6.3.Final休眠休眠,JPA 2.0-api-1.0.0.Final提供 随着春天的3.0.5 RELEASE库 但我正在逐渐而AppContext加载follwoing错误: 抛出java.lang.ClassNotFoundException:org.hibernate.annotations.common.reflection.ReflectionManager在EnvironmentClassLoader. 看起来我可能会丢失Hibernate的注解

  • 柔性BlazeDS的春天休眠 2014-06-05

    我尝试启动的Java EE,因此,研究适用于该架构框架之后,我选择使用下列之一:Flex中,BlazeDS的,春天,休眠,MySQL的. 我将与Eclipse或STS工作. 问题在于,遍布网络教程尝试不同的项目后,我是不是能够创建收集所有版本的最后关闭技术我选择的架构. SO,有人可以给我这是指一个教程的地方是最好的源代码可以下载一个环节,它给什么做的解释. --------------解决方案------------- 说明:http://sebastien-arbogast.com/2009

  • Java的春天:AnnotationSessionFactoryBean,Hibernate的方言自动检测 2014-12-29

    我用下面的Spring应用程序上下文: <!-- Hibernate session factory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSou

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.532 (s). 10 q(s)