integrazione di spring 3, hibernate 3, maven e mysql

Ho provato diverse sessionFactory in applicationContext.xml. ha lo stesso problema. qualsiasi consiglio sarebbe apprezzato in anticipo! applicationContext.xml

                              ${jdbc.dialect}   ${hibernate.show_sql}   ${hibernate.format_sql}     

ecco il pom.xml.

  4.0.0 org.peterhuang myweb war 0.0.1-SNAPSHOT myweb Maven Webapp http://maven.apache.org    junit junit 3.8.1 test    org.springframework spring-core 3.2.4.RELEASE   org.springframework spring-webmvc 3.2.4.RELEASE   org.springframework spring-context 3.2.4.RELEASE   org.springframework spring-orm 3.2.4.RELEASE   org.springframework spring-hibernate3 2.0.8   org.springframework spring-tx 3.2.4.RELEASE    org.hibernate hibernate-core 4.2.6.Final    jstl jstl 1.2    javax.transaction jta 1.1    mysql mysql-connector-java 5.1.26    myweb  

ecco la traccia di errore. Lo sto eseguendo all’interno di eclipse, su server tomcat 7

 SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) 

CategoryDAOImpl

 package org.peterhuang.myweb.dao.impl; import java.util.List; import org.hibernate.SessionFactory; import org.peterhuang.myweb.dao.CategoryDAO; import org.peterhuang.myweb.model.Category; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @Repository(value = "categoryDAO") public class CategoryDAOImpl implements CategoryDAO { @Autowired private SessionFactory sessionFactory; @SuppressWarnings("unchecked") public List getCategoryList() { // TODO Auto-generated method stub return (List) sessionFactory.openSession() .getNamedQuery("findAllCategory").list(); } public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } } 

CategoryDAO

 package org.peterhuang.myweb.dao; import java.util.List; import org.springframework.stereotype.Service; import org.peterhuang.myweb.model.*; @Service public interface CategoryDAO { public List getCategoryList(); } 

Category.java

 package org.peterhuang.myweb.model; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; @NamedQueries({ @NamedQuery(name = "findAllCategory", query = "from CATEGORY s ") }) @Entity @Table(name = "CATEGORY") public class Category { @Id @Column(name = "CATEGORY_ID") @GeneratedValue private int id; @Column(name = "CATEGORY_NAME") private String categoryName; public Category() { } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getCategoryName() { return categoryName; } public void setCategoryName(String categoryName) { this.categoryName = categoryName; } } 

PageController.java

 package org.peterhuang.myweb.web; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.peterhuang.myweb.dao.impl.CategoryDAOImpl; import org.peterhuang.myweb.model.Category; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class PageController { @Resource private CategoryDAOImpl categoryDAOImpl; @RequestMapping(value = "/mainpage") public String mainPage(Model model, HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); List categoryList = categoryDAOImpl.getCategoryList(); System.out.println(categoryList); session.setAttribute("categoryList", categoryList); return "mainpage"; } } 

web.xml

   my web  dispatcher org.springframework.web.servlet.DispatcherServlet  contextConfigLocation /WEB-INF/applicationContext.xml  1   dispatcher /*   org.springframework.web.context.ContextLoaderListener   /index.jsp  

Hai una situazione infernale da JAR.

Per qualsiasi motivo, questa dipendenza

  org.springframework spring-hibernate3 2.0.8  

che ha una class org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean nasconde la class org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean , es. stesso nome, in questa dipendenza

  org.springframework spring-orm 3.2.4.RELEASE  

E quella class non ha un metodo setPackagesToScan . Sbarazzarsi della dipendenza dalla spring-hibernate3 . spring-orm dovrebbe essere più che sufficiente. Puoi scaricare la fonte qui e controllare da soli.

Penso che il problema sia che i packagesToScan proprietà packagesToScan occupano un String array piuttosto che una semplice String . Prova a cambiare la proprietà da:

a

   org.peterhuang.myweb