I think I've really narrowed this down. What I've tried to do is rework the "MyEclipse Hibernate and Spring Tutorial" from a Java Project into a Web Project running under GlassFish. It's sort of a cross between that tutorial and the "Java EE 5 MyBlog Application Demo"
So, instead of a "main", I have a .JSP with a backing backing bean doing much the same functionality as the "main." I was hoping to offer this as a tutorial piece for web/hibernate/spring. Here's what happens
I call a method in the backing bean with a commandButton in the main JSP. Right now, all I'm trying to do is the following:
public String doPost() {
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory.getBean("persistenceLayer");
return "success";
}
It's throwing up on the PersistenceLayer line with the following error...
javax.servlet.ServletException: #{mainBean.doPost}: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceLayer' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'UserDAO' while setting bean property 'userDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserDAO' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'hibernateSession' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSession' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
.
My applicationContext.xml is almost identical to that of the tutorial...
<?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">
<bean id="hibernateSession" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
<bean id="persistenceLayer" class="com.lmco.hibernatespring.PersistenceLayer" abstract="false" scope="singleton" lazy-init="default" autowire="default"
dependency-check="default">
<property name="userDAO">
<ref bean="UserDAO" />
</property>
</bean>
<bean id="UserDAO" class="com.lmco.hibernatespring.UserDAO">
<property name="sessionFactory">
<ref bean="hibernateSession" />
</property>
</bean>
</beans>
The PersistenceLayer.java is exactly the same as in the tutorial...
package com.lmco.hibernatespring;
public class PersistenceLayer {
private UserDAO userDAO;
public UserDAO getUserDAO() {
return userDAO;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
public void addUser(User user) {
userDAO.save(user);
}
public User findUserById(Integer id) {
return userDAO.findById(id);
}
public void updateUser(User user) {
userDAO.merge(user);
}
public void deleteUser(User user) {
userDAO.delete(user);
}
}
I really want this to work so there can be a web version of that tutorial, but I can't understand why it doesn't like the PersistenceLayer.
If I can get help getting this thing to work, I think it will really help other user have a nice starting point for a web/jsf/spring/hibernate project.