4
回答
自己定义的一个listener 在web.xml配置 为神马显示NameNotFoundException呢?
注册华为云得mate10,2.9折抢先购!>>>   

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


	<!-- 对Spring容器进行实例化 -->
	<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>

	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<!-- struts2容器控制器 -->
	    
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	 
	<session-config>
		<session-timeout>10</session-timeout>
	</session-config>
	<listener>
		<listener-class>com.yjj.sk.listener.UserLoginListener</listener-class>
	</listener>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>


UserLoginListener.java

package com.yjj.sk.listener;

import javax.annotation.Resource;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.yjj.sk.auth.model.Uuser;
import com.yjj.sk.auth.service.UserService;

public class UserLoginListener implements HttpSessionListener {
	@Resource
	private UserService userService;
	private Uuser user;

	public void sessionCreated(HttpSessionEvent arg0) {

	}

	public void sessionDestroyed(HttpSessionEvent se) {
		user = (Uuser)se.getSession().getAttribute("user");
		if(user!=null){
			System.out.println(userService);
		}
	}

}
异常

严重: Error configuring application listener of class com.yjj.sk.listener.UserLoginListener
javax.naming.NameNotFoundException: Name com.yjj.sk.listener.UserLoginListener is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)


<无标签>
举报
duoduo3_69
发帖于5年前 4回/2K+阅
顶部