因为最近公司的项目也不是很紧张,所以自己想抽空学学东西,于是下载了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 

解决方案 »

  1.   

    貌似是你的dataSource配置有问题
      

  2.   

    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有问题之类的!
      

  3.   

    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? 
      

  4.   

    'dataSource' is not writable or has an invalid setter method.已经写的很明白了!
      

  5.   

    怎么配置中所有用到classpath的地方都带上"*"呢?
      

  6.   

    都说csdn是高手,可是高手在哪里呢?
    这样的问题一直困扰着我好久了。却总是不见一个人出来
      

  7.   


    我经理说了,CSDN上面有高手,但都潜水,像我们大部分人都是刚上路的所以建议,去多点sun的Java社区,那的人热闹啊
      

  8.   

    有什么好争得 写的垃圾东西  使用myclipse添加spring支持 然后jpa支持,如果你想使用自己的jar文件,移除一下不就得了,还有一点就是jar包要兼容