本文介绍了初始化bean失败;嵌套异常是org.springframework.beans的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
sdnext-servlet.xml
< bean id =sessionFactory
class =org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean>
< property name =dataSourceref =dataSource/>
< property name =annotatedClasses>
< list>
< value> com.anand.model.Employee< / value>
< / list>
< / property>
< property name =hibernateProperties>
<道具>
< prop key =hibernate.dialect> $ {hibernate.dialect}< / prop>
< prop key =hibernate.show_sql> $ {hibernate.show_sql}< / prop>
< prop key =hibernate.hbm2ddl.auto> $ {hibernate.hbm2ddl.auto}< / prop>
< /道具>
< / property>
< / bean>
模型类:Employee.java
package com.anand.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
* @author Anand Gopalan
*
* /
@Entity
@Table(name =Employee)
public class Employee实现Serializable {
private static final long serialVersionUID = -723583058586873479L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name =empid)
private Integer empId;
@Column(name =empname)
private String empName;
@Column(name =empaddress)
private String empAddress;
@Column(name =薪水)
私人长期工资;
@Column(name =empAge)
private Integer empAge;
public Integer getEmpId(){
return empId;
}
public void setEmpId(Integer empId){
this.empId = empId;
}
public String getEmpName(){
return empName;
}
public void setEmpName(String empName){
this.empName = empName;
}
public String getEmpAddress(){
return empAddress;
}
public void setEmpAddress(String empAddress){
this.empAddress = empAddress;
}
public Long getSalary(){
return salary;
}
public void setSalary(长工资){
this.salary = salary;
}
public Integer getEmpAge(){
return empAge;
}
public void setEmpAge(Integer empAge){
this.empAge = empAge;
}
}
日志:
解决方案
这是你所做的一个选择。尝试用你的配置文件中的以下元素替换 annotatedClasses
,并在此之后清理构建工作区+重新启动服务器。
< property name =packagesToScan>
< list>
< value> com.anand.model< / value>
< / list>
< / property>
sdnext-servlet.xml
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.anand.model.Employee</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
Model Class : Employee.java
package com.anand.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author Anand Gopalan
*
*/
@Entity
@Table(name="Employee")
public class Employee implements Serializable{
private static final long serialVersionUID = -723583058586873479L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "empid")
private Integer empId;
@Column(name="empname")
private String empName;
@Column(name="empaddress")
private String empAddress;
@Column(name="salary")
private Long salary;
@Column(name="empAge")
private Integer empAge;
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpAddress() {
return empAddress;
}
public void setEmpAddress(String empAddress) {
this.empAddress = empAddress;
}
public Long getSalary() {
return salary;
}
public void setSalary(Long salary) {
this.salary = salary;
}
public Integer getEmpAge() {
return empAge;
}
public void setEmpAge(Integer empAge) {
this.empAge = empAge;
}
}
Logs:
解决方案
This is an alternative to what you have done. Try to replace the annotatedClasses
with that of the following element in your config and clean build your workspace after that + restart your server .
<property name="packagesToScan">
<list>
<value>com.anand.model</value>
</list>
</property>
这篇关于初始化bean失败;嵌套异常是org.springframework.beans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!