这个bug怎么解决啊??一直报错。。

乐之者v 2017-05-15 10:40:55
报错:
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerServiceImpl': Injection of persistence fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: WEB-INF/classes/com/sanqing/po/Quotation (wrong name: com/sanqing/po/Quotation)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: WEB-INF/classes/com/sanqing/po/Quotation (wrong name: com/sanqing/po/Quotation)

Caused by: java.lang.NoClassDefFoundError: WEB-INF/classes/com/sanqing/po/Quotation (wrong name: com/sanqing/po/Quotation)
我搜索了好久,还是解决不了问题。。
以下是beans.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 配置哪些包下的类需要自动扫描 -->
<context:component-scan base-package="com.sanqing"/>

<!-- 这里的jun要与persistence.xml中的 <persistence-unit name="jun" transaction-type="RESOURCE_LOCAL">
中的name值要一致,这样才能找到相关的数据库连接
-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="jun"/>
</bean>
<!-- 配置事物管理器 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- 配置使用注解来管理事物 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

</beans>

下面这个是persistence.xml


<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="jun" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect"/><!--数据库方言-->
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver"/><!--数据库驱动类-->
<property name="hibernate.connection.username" value="root"/><!--数据库用户名-->
<property name="hibernate.connection.password" value="root"/>
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/quote;"/><!--数据库连接URL-->
<property name="hibernate.max_fetch_depth" value="3"/><!--外连接抓取树的最大深度 -->
<property name="hibernate.hbm2ddl.auto" value="update"/><!-- 自动输出schema创建DDL语句 -->
<property name="hibernate.jdbc.fetch_size" value="18"/><!-- JDBC的获取量大小 -->
<property name="hibernate.jdbc.batch_size" value="10"/><!-- 开启Hibernate使用JDBC2的批量更新功能 -->
<property name="hibernate.show_sql" value="true"/><!-- 在控制台输出SQL语句 -->
</properties>
</persistence-unit>
</persistence>


快两天了,还是没解决。。求助。。
...全文
310 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
乐之者v 2017-05-16
  • 打赏
  • 举报
回复
引用 4 楼 ScottJane 的回复:
Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: WEB-INF/classes/com/sanqing/po/Quotation (wrong name: com/sanqing/po/Quotation) 这段话的意思是创建entityManagerFactory出错,初始化失败,没有找到默认的类,要找的是WEB-INF/classes/com/sanqing/po/Quotation,给的是 com/sanqing/po/Quotation,原因有可能是classpath有问题或者注解有问题。应该和persistence.xml没有关系。和customerServiceImpl更加没有关系!出错的时候还没有到这一层呢。
注解真的报错了。。@Entity @Table(name="tb_customer") 这里的Table无法解析。。然后我关联了数据源,但是还是报错。。 我的数据库里面只有这个表,tb_customer,里面没有数据。。是这个原因吗?
roa_finder 2017-05-16
  • 打赏
  • 举报
回复
NoClassDefFoundError 是jar包有问题没有加载进去
ScottJane 2017-05-16
  • 打赏
  • 举报
回复
Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: WEB-INF/classes/com/sanqing/po/Quotation (wrong name: com/sanqing/po/Quotation) 这段话的意思是创建entityManagerFactory出错,初始化失败,没有找到默认的类,要找的是WEB-INF/classes/com/sanqing/po/Quotation,给的是 com/sanqing/po/Quotation,原因有可能是classpath有问题或者注解有问题。应该和persistence.xml没有关系。和customerServiceImpl更加没有关系!出错的时候还没有到这一层呢。
laoli&laowang 2017-05-16
  • 打赏
  • 举报
回复
找不到这个类Quotation
墨笙弘一 2017-05-16
  • 打赏
  • 举报
回复
赞同楼上的说法
  • 打赏
  • 举报
回复
Error creating bean with name 'customerServiceImpl': Injection of persistence fields failed 应该是创建名字为customerServiceImpl的bean出现错误,找不到类 WEB-INF/classes/com/sanqing/po/Quotation (wrong name: com/sanqing/po/Quotation。应该是jar包的引用问题。
乐之者v 2017-05-16
  • 打赏
  • 举报
回复
引用 6 楼 sinat_32502451 的回复:
[quote=引用 4 楼 ScottJane 的回复:] Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: WEB-INF/classes/com/sanqing/po/Quotation (wrong name: com/sanqing/po/Quotation) 这段话的意思是创建entityManagerFactory出错,初始化失败,没有找到默认的类,要找的是WEB-INF/classes/com/sanqing/po/Quotation,给的是 com/sanqing/po/Quotation,原因有可能是classpath有问题或者注解有问题。应该和persistence.xml没有关系。和customerServiceImpl更加没有关系!出错的时候还没有到这一层呢。
注解真的报错了。。@Entity @Table(name="tb_customer") 这里的Table无法解析。。然后我关联了数据源,但是还是报错。。 我的数据库里面只有这个表,tb_customer,里面没有数据。。是这个原因吗?[/quote] 终于解决了。。在数据库内建了表,各种列名都写上了,然后关联数据库,注解就不会报错了。
ScottJane 2017-05-16
  • 打赏
  • 举报
回复
com/sanqing/po/Quotation 肯定和这个有点关系,你这个类是什么类?

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧