DefaultInstanceManager无法使用修饰符“”访问类的成员

时间:2012-08-30 07:44:22

标签: jsf-2 tomcat7 servlet-filters

不确定这里有什么问题,请帮忙。 这是例外:

SEVERE: Exception starting filter com.bannerplay.beans.LoginFilter
java.lang.IllegalAccessException: Class org.apache.catalina.core.DefaultInstanceManager can not access a member of class com.bannerplay.beans.LoginFilter with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:134)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

login.xhtml

<h:form>
    Username : <h:inputText value="#{loginBean.username}" />
    Password : <h:inputSecret value="#{loginBean.password}" />
<h:commandButton value="Login" action="#{loginBean.checkLogin}" />
</h:form>

的web.xml

  <filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.bannerplay.beans.LoginFilter</filter-class>
  </filter>
  <filter-mapping>
<filter-name>LoginFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/admin/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
     <welcome-file>/login.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
       <servlet-name>FacesServlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
  </servlet>
  ...

和LoginFilter.java

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@WebFilter("/admin/*")
class LoginFilter implements Filter {
@Override
public void doFilter(ServletRequest request , ServletResponse response , FilterChain chain) throws ServletException, IOException {
    HttpSession session = ((HttpServletRequest) request).getSession();
    UserBean userBean = (UserBean) session.getAttribute("userBean");
    if (userBean != null) {
        User user = userBean.getUser();
        if (user == null) {
            ((HttpServletResponse) response).sendRedirect("/login.xhtml");
        } else
            chain.doFilter(request, response);
    } else
        ((HttpServletResponse) response).sendRedirect("/login.xhtml");
}

public void init(FilterConfig fc) {
}

public void destroy() {
}
}

我不知道这个例外的来源,请对这个问题有所了解。谢谢!

EDIT1:添加UserBean.java代码:

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
class UserBean implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = 1L;

public User getUser() {
    return user;
}

public void setUser(User user) {
    this.user = user;
}

private User user;
}

BTW,严重:由于先前的错误,上下文[/ projectName]启动失败

2 个答案:

答案 0 :(得分:12)

更改:

class LoginFilter implements Filter {

public class LoginFilter implements Filter {

答案 1 :(得分:5)

对我来说问题是&#39;构造函数&#39;不是public