を休止したい:は春4とのhbm.xmlファイルの使用を避け、私はエラーの下に取得しようとした5
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mysessionFactory' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'packageToScan' of bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean]: Bean property 'packageToScan' is not writable or has an invalid setter method. Did you mean 'packagesToScan'?
ここで私はのHibernateTemplateの助けを借りて、データベースに接続しようと休止状態5と春を使用しています4バージョン。
spring-dispatcher-servlet.xml
:以下
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<context:component-scan base-package="com.annotations" />
<context:component-scan base-package="com.controller" />
<context:annotation-config />
<mvc:annotation-driven/>
<bean id="emp" class="com.model.Employee">
<property name="id" value="001"/>
<property name="name" value="Chitta"/>
<property name="salary" value="9999"/>
</bean>
<bean id="dmds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"></property>
<property name="username" value="system"></property>
<property name="password" value="[email protected]"></property>
</bean>
<bean id="mysessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dmds"></property>
<property name="packageToScan" value="com.model"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle12cDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="mysessionFactory"/>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="mysessionFactory"></property>
<!-- <property name="checkWriteOperations" value="false"></property> -->
</bean>
<bean id="eDAO" class="com.dao.EmployeeDAO">
<property name="template" ref="hibernateTemplate"></property>
</bean>
<bean id="sevImpl" class="com.service.onlineServicesImpl">
<property name="eDAO" ref="eDAO"></property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
私はspring-dispatcher.xml
ファイルに言及しています私のモデルクラスです。私のコードはhbm.xml
で正常に動作していますが、私はhbm
ファイルの使用を避けたいと思います。とにかく問題を解決できるのですか?
Employee.java
:あなたは、なぜあなたはすべてのXMLファイルを使用している休止状態5と春4を使用している場合
package com.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table (name = "emp558", schema = "DB_USER")
public class Employee {
@Id
private String id;
@Column
private String name;
@Column
private String salary;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSalary() {
return salary;
}
public void setSalary(String salary) {
this.salary = salary;
}
}
に
<property name="packagesToScan" value="com.model">
へ<property name="packageToScan" value="com.model">
を置き換えますか? Javaコードだけですべてを行うことができます!また、Springブートを使用すると、多くのBoilerplateデータソース/ JPA設定を自分で保存することができます。 –