spring + struts + hibernate

来源:百度知道 编辑:UC知道 时间:2024/06/05 03:53:28
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/login' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
application。xml没有问题
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation"
value="/WEB-INF/hibernate.cfg.xml">
</property>
</bean>

<bean id="AdminUserDAO" class="com.dao.AdminUserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="AdminUserService" class="com.service.A

没有在web.xml中定义spring的监听器

需要在web.xml中加入:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

no ContextLoaderListener registered? ---表示 [/WEB-INF/applicationContext.xml]中没有配置spring的listener.所以spring不能初始化你的beansFactory.

在你的[/WEB-INF/applicationContext.xml]中加上:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

/WEB-INF/applicationContext.xml
里面没有定义名字是 /login 的bean

你这个配置就有很多毛病

定义一个bean,怎么弄个name="/login"?,
这个无所谓

<bean name="/login">里配的