2012-04-16 20 views
1

私はDAOとBOのクラスを使用する方法を学習しようとしていると私は、次のエラーセッターのパラメータ型がゲッタの戻り型と一致していますか?

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring/database/Hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'annotatedClasses' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 

Hibernate.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" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

<!-- Hibernate session factory --> 
<bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
<!--class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">--> 
<property name="dataSource"> 
    <ref bean="dataSource"/> 
</property> 

<property name="configLocation">  
    <value>classpath:spring/database/hibernate.cfg.xml 
    </value> 
</property> 

<property name="hibernateProperties"> 
    <props> 
    <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> 
    <prop key="hibernate.show_sql">true</prop> 
    </props> 
</property> 

    <property name="annotatedClasses"> 
<list> 
    <value>com.fexco.helloworld.web.model.Customer</value> 
    <value>com.fexco.helloworld.web.model.Countries</value> 
</list> 
</property> 

</bean> 

DataSource.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

<bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
<property name="location"> 
    <value>/properties/database.properties</value> 
</property> 
</bean> 

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
<property name="driverClassName" value="${database.driverClassName}" /> 
<property name="url" value="${database.url}" /> 
<property name="username" value="${database.username}" /> 
<property name="password" value="${database.password}" /> 
</bean> 


<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="packagesToScan" value="data" /> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop> 
      <prop key="hibernate.current_session_context_class">thread</prop> 
      <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop> 
      <prop key="hibernate.show_sql">true</prop> 
      <prop key="hibernate.hbm2ddl.auto">update</prop> 
     </props> 
    </property> 
</bean> 
を取得しています

countries.javaクラスとcustomer.javaクラスのgetterメソッドとsetterメソッドがすべて正しいため、エラーの原因がわかりません。

誰かが間違っていることを知っていますか?

答えて

6

、あなたはそれを持っていませんLocalSessionFactoryBeanを使用している(あなたはがそれを持っているAnnotationSessionFactoryBeanことをコメントしています)。

+0

ああ、私はそれが働いていて、それを変更した後、それを元気づけていました。 – newSpringer

1

はあなたがいる一方で、もともとAnnotationSessionFactoryBeanから来る「annotatedClasses」プロパティを設定したいように見える

おかげで(あなたが他のクラスのいずれかを確認する必要がある場合は、単にクラスとILポストそれらをコメントことわざを追加)このプロパティを持たないLocalSessionFactoryBeanを実際に使用しています。これは、実際にセッションファクトリのannotatedClasses財産文句だ

関連する問題