按黎活明老师的巴巴运动网视频整合时出现问题(解决有分送)

伤寒泪 2009-09-21 02:30:13
因为最近公司的项目也不是很紧张,所以自己想抽空学学东西,于是下载了CZBK的巴巴运动网视频,但是在整合spring+jpa的时候出现了问题,一直难于解决,看了很多文章,知道了那个是类装载的问题,但是确实是能力有限,看不懂那些高手的回答。

谁能给我解答一下,感激不尽,我用的容器时tomcat6.0 我把我的配置发出来

persistence.xml

Xml代码
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="1.0" 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">
<persistence-unit name="fraemwork" transaction-type="RESOURCE_LOCAL">
<class>org.hibernate.ejb.HibernatePersistence </class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.jdbc.fetch_size" value="50"/>
<property name="hibernate.jdbc.batch_size" value="30"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>

<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="1.0" 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">
<persistence-unit name="fraemwork" transaction-type="RESOURCE_LOCAL">
<class>org.hibernate.ejb.HibernatePersistence </class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.jdbc.fetch_size" value="50"/>
<property name="hibernate.jdbc.batch_size" value="30"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>


applicationContext.xml

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: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">


<context:annotation-config> </context:annotation-config>
<context:component-scan base-package="com.tomaer" />
<context:property-placeholder location="classpath*:jdbc.properties"/>
<context:property-placeholder location="classpath*:memcached.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>

<!-- 事务管理器配置 -->
<!--
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven transaction-manager="txManager"/>
-->
</beans>

<?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: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">


<context:annotation-config> </context:annotation-config>
<context:component-scan base-package="com.tomaer" />
<context:property-placeholder location="classpath*:jdbc.properties"/>
<context:property-placeholder location="classpath*:memcached.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>

<!-- 事务管理器配置 -->
<!--
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven transaction-manager="txManager"/>
-->
</beans>


看了大家的帖子,我也在tomcat的lib目录下面放入了spring-tomcat-weaver.jar。和persistence.xml同路径下放入了context.xml

内容如下

Xml代码
<?xml version="1.0" encoding="UTF-8" ?>
<Context path="/fraemwork" docBase="C:/java/fraemwork/WebRoot" reloadable="true">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
useSystemClassLoaderAsParent="false"/>
<WatchedResource>WEB-INF/web.xml </WatchedResource>
</Context>

<?xml version="1.0" encoding="UTF-8" ?>
<Context path="/fraemwork" docBase="C:/java/fraemwork/WebRoot" reloadable="true">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
useSystemClassLoaderAsParent="false"/>
<WatchedResource>WEB-INF/web.xml </WatchedResource>
</Context>


启动时候就会报这样的异常

希望高手可以告诉我 需要怎么做。谢谢
这里限制发帖字数。请看这个
http://www.javaeye.com/problems/25544
...全文
195 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jun88love123 2011-02-17
  • 打赏
  • 举报
回复
我正在学习这套视频教程那
Iwillgohome 2009-09-29
  • 打赏
  • 举报
回复
有什么好争得 写的垃圾东西 使用myclipse添加spring支持 然后jpa支持,如果你想使用自己的jar文件,移除一下不就得了,还有一点就是jar包要兼容
狼里格东 2009-09-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 tomaery 的回复:]
都说csdn是高手,可是高手在哪里呢?
这样的问题一直困扰着我好久了。却总是不见一个人出来
[/Quote]

我经理说了,CSDN上面有高手,但都潜水,像我们大部分人都是刚上路的

所以建议,去多点sun的Java社区,那的人热闹啊
tomaery 2009-09-28
  • 打赏
  • 举报
回复
都说csdn是高手,可是高手在哪里呢?
这样的问题一直困扰着我好久了。却总是不见一个人出来
tomaery 2009-09-22
  • 打赏
  • 举报
回复
难道不带*吗?这个其实应该无所谓吧
mcdido 2009-09-21
  • 打赏
  • 举报
回复
怎么配置中所有用到classpath的地方都带上"*"呢?
woming66 2009-09-21
  • 打赏
  • 举报
回复
'dataSource' is not writable or has an invalid setter method.

已经写的很明白了!
伤寒泪 2009-09-21
  • 打赏
  • 举报
回复
请大家帮忙好好的解决下呢。。
bangyulin 2009-09-21
  • 打赏
  • 举报
回复
Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
liangwansheng 2009-09-21
  • 打赏
  • 举报
回复
我也不知道是什么错误,但是配置文件中一定不要有没用到的语句。
qsrock 2009-09-21
  • 打赏
  • 举报
回复
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/F:/apache-tomcat-6.0.18/webapps/fraemwork/WEB-INF/classes/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.jpa.LocalEntityManagerFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?


entityManagerFactory创建失败,是不是配置dataSource的时候哪里写错了哦!
是不是setter method有问题之类的!
伤寒泪 2009-09-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yagexury 的回复:]
貌似是你的dataSource配置有问题
[/Quote]

请教仁兄。、能具体说说么?
yagexury 2009-09-21
  • 打赏
  • 举报
回复
貌似是你的dataSource配置有问题
healer_kx 2009-09-21
  • 打赏
  • 举报
回复
什么意思?
dahaidao 2009-09-21
  • 打赏
  • 举报
回复
没弄过这个啊,帮你顶一下吧。

81,091

社区成员

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

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