使用Spring

时间:2017-04-15 16:18:18

标签: java spring jsp

美好的一天当我尝试运行我的代码时,我有这个严重错误我要做什么?  这是例外:

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'homeController'的bean时出错:通过字段'eventiDao'表示的不满意的依赖关系;嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'eventiDaoImpl'的bean时出错:通过字段'sessionFactory'表示的不满意依赖;嵌套异常是org.springframework.beans.factory.BeanCreationException:在ServletContext资源[/WEB-INF/applicationContext.xml]中定义了名为'sessionFactory'的bean时出错:init方法的调用失败;嵌套异常是java.lang.NoSuchMethodError:javax.persistence.Table.indexes()[Ljavax / persistence / Index;

的HomeController

@Controller

public class HomeController {

@Autowired
private EventiDaoImpl eventiDao;

@RequestMapping("/")
public String home(){
    return "home";
}

@RequestMapping("/eventi")
public String getEventi(Model model){
    List<EventiEntity> eventi= eventiDao.getListaEventi();
    model.addAttribute("eventi", eventi);
    return "eventi";
}

}

调度员的servlet

<?xml version="1.0" encoding="UTF-8"?>
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
</bean>
<mvc:resources mapping="/public/**" location="/WEB-INF/public/"/>
<tx:annotation-driven/>

的applicationContext

<?xml version="1.0" encoding="UTF-8"?>
<context:component-scan base-package="com.community"/>
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
</bean>
<mvc:resources mapping="/public/**" location="/WEB-INF/public/"/>
<tx:annotation-driven/>

EventiDaoImpl

@Repository

@Transactional 公共类EventiDaoImpl实现了EventiDao {

@Autowired
private SessionFactory sessionFactory;

public void addEvento(EventiEntity evento) {
    Session session = sessionFactory.getCurrentSession();
    session.saveOrUpdate(evento);
    session.flush();
}

public EventiEntity getEventoById(int id) {
    Session session = sessionFactory.getCurrentSession();
    EventiEntity evento = (EventiEntity) session.get(EventiEntity.class, id);
    session.flush();
    return evento;
}

public List<EventiEntity> getListaEventi() {
    Session session = sessionFactory.getCurrentSession();
    Query query = session.createQuery("FROM EVENTI");
    List<EventiEntity> eventi = query.list();
    session.flush();
    return eventi;
}

public void deleteEvento(int id) {
    Session session = sessionFactory.getCurrentSession();
    session.delete(getEventoById(id));
    session.flush();
}

public List<EventiEntity> getNextEventi(){
    Session session = sessionFactory.getCurrentSession();
    Query query = session.createQuery("FROM EVENTI WHERE data>=current_date ");
    List<EventiEntity> eventi = query.list();
    session.flush();
    return eventi;
}

} EventiEntity

@Entity

@Table(name =“EVENTI”,schema =“uda_benato”) 公共课EventiEntity {

@Autowired

private int idEvento;
private String titolo;
private String luogo;
private String provincia;
private String descrizione;
private Date data;
private CategorieEntity categoria;

@Id
@Column(name = "idEvento")
public int getIdEvento() {
    return idEvento;
}

public void setIdEvento(int idEvento) {
    this.idEvento = idEvento;
}

@Basic
@Column(name = "titolo")
public String getTitolo() {
    return titolo;
}

public void setTitolo(String titolo) {
    this.titolo = titolo;
}

@Basic
@Column(name = "luogo")
public String getLuogo() {
    return luogo;
}

public void setLuogo(String luogo) {
    this.luogo = luogo;
}

@Basic
@Column(name = "provincia")
public String getProvincia() {
    return provincia;
}

public void setProvincia(String provincia) {
    this.provincia = provincia;
}

@Basic
@Column(name = "descrizione")
public String getDescrizione() {
    return descrizione;
}

public void setDescrizione(String descrizione) {
    this.descrizione = descrizione;
}

@Basic
@Column(name = "data")
public Date getData() {
    return data;
}

public void setData(Date data) {
    this.data = data;
}


@ManyToOne
@Column(name="categoria")
public CategorieEntity getCategoria(){return categoria;}

public void setCategoria(CategorieEntity categoria){this.categoria=categoria;}
@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    EventiEntity that = (EventiEntity) o;

    if (idEvento != that.idEvento) return false;
    if (titolo != null ? !titolo.equals(that.titolo) : that.titolo != null) return false;
    if (luogo != null ? !luogo.equals(that.luogo) : that.luogo != null) return false;
    if (provincia != null ? !provincia.equals(that.provincia) : that.provincia != null) return false;
    if (descrizione != null ? !descrizione.equals(that.descrizione) : that.descrizione != null) return false;
    if (data != null ? !data.equals(that.data) : that.data != null) return false;

    return true;
}

@Override
public int hashCode() {
    int result = idEvento;
    result = 31 * result + (titolo != null ? titolo.hashCode() : 0);
    result = 31 * result + (luogo != null ? luogo.hashCode() : 0);
    result = 31 * result + (provincia != null ? provincia.hashCode() : 0);
    result = 31 * result + (descrizione != null ? descrizione.hashCode() : 0);
    result = 31 * result + (data != null ? data.hashCode() : 0);
    return result;
}

}

0 个答案:

没有答案