Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Tomcat/ApplicationContext无法找到筛选器类_Java_Spring Mvc_Tomcat_Maven 3_Applicationcontext - Fatal编程技术网

Java Tomcat/ApplicationContext无法找到筛选器类

Java Tomcat/ApplicationContext无法找到筛选器类,java,spring-mvc,tomcat,maven-3,applicationcontext,Java,Spring Mvc,Tomcat,Maven 3,Applicationcontext,web.xml 自助服务门户 home.html default.html 克斯菲尔特 org.apache.catalina.filters.CorsFilter cors.methods 获取、发布、放置、删除、选项、标题 克斯菲尔特 /* 登录 com.app.api.filter.AuthenticationFilter 登录 /* 调度员 org.springframework.web.servlet.DispatcherServlet 1. 调度员 /* org.springfra

web.xml


自助服务门户
home.html
default.html
克斯菲尔特
org.apache.catalina.filters.CorsFilter
cors.methods
获取、发布、放置、删除、选项、标题
克斯菲尔特
/*
登录
com.app.api.filter.AuthenticationFilter
登录
/*
调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/*
org.springframework.web.context.ContextLoaderListener
上下文配置位置
classpath*:applicationContext*.xml
自定义筛选器类:-

package com.app.api.filter;
导入java.io.IOException;
导入java.util.HashMap;
导入java.util.Map;
导入javax.servlet.Filter;
导入javax.servlet.FilterChain;
导入javax.servlet.FilterConfig;
导入javax.servlet.ServletException;
导入javax.servlet.ServletRequest;
导入javax.servlet.ServletResponse;
导入javax.servlet.annotation.WebFilter;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
导入javax.servlet.http.HttpSession;
导入org.slf4j.Logger;
导入org.slf4j.LoggerFactory;
导入org.springframework.http.MediaType;
导入com.fasterxml.jackson.databind.ObjectMapper;
@WebFilter(“/*”)
公共类AuthenticationFilter实现筛选器{
私有静态最终记录器Logger=LoggerFactory.getLogger(AuthenticationFilter.class);
公共身份验证筛选器(){
System.out.println(“身份验证-默认过滤器!”);
}
公共空间销毁(){
System.out.println(“身份验证-销毁!”);
}
public void doFilter(ServletRequest请求、ServletResponse响应、FilterChain链)抛出IOException、ServletException{
debug(“请求身份验证!”);
HttpServletRequest httpRequest=(HttpServletRequest)请求;
字符串uri=httpRequest.getRequestURI();
if(uri.equals(“/app-api/login”)| uri.equals(“/app-api/logout”)){
链式过滤器(请求、响应);
返回;
}
HttpSession session=httpRequest.getSession(false);
if(session==null | | session.getAttribute(“用户”)==null){
writeInvalidCredentialResponse((HttpServletResponse)响应);
}否则{
链式过滤器(请求、响应);
}
}
私有void writeInvalidCredentialResponse(HttpServletResponse响应)引发IOException{
Map errorResponse=newhashmap();
errorResponse.put(“消息”,“请使用正确的凭据登录!”);
ObjectMapper mapper=新的ObjectMapper();
String responseMessage=mapper.writeValueAsString(errorResponse);
debug(“无效的请求验证!”);
LOGGER.debug(响应消息);
response.getWriter().write(responseMessage);
response.setContentType(MediaType.APPLICATION\u JSON\u值);
response.setStatus(HttpServletResponse.SC_未经授权);
}
public void init(FilterConfig fConfig)抛出ServletException{
System.out.println(“Authentication-init!”);
}
}
项目层次结构:-

A-父maven模块

B-RESTfulWebservices子模块(包含-/WEB-INF/WEB.xml、/WEB-INF/DispatcherServlet.xml)

C-持久层子模块(包含-/resources/applicationContext.xml、/resources/persistence.xml)

请帮助我解决这个问题,使我的spring上下文启动并运行(ui-webservices和持久性) 非常感谢

应用程序接口 /app api/src/main/webapp/WEB-INF/dispatcher-servlet.xml


应用程序数据 /app data/src/main/resources/applicationContext-data.xml



尝试删除@WebFilter,并确保您的init方法重写,因为我们在提供的代码中看不到这一点

尝试删除@WebFilter并确保您的init方法重写,因为我们在提供的代码中看不到这一点

让我们看看例外情况:

java.lang.ClassNotFoundException: com.adobe.ssp.api.filter.AuthenticationFilter

类路径有问题,找不到类“com.adobe.ssp.api.filter.AuthenticationFilter”。请确保此类包含在:您的\u-APP\WEB-INF\classes您的\u-APP\WEB-INF\lib

让我们看看例外情况:

java.lang.ClassNotFoundException: com.adobe.ssp.api.filter.AuthenticationFilter

类路径有问题,找不到类“com.adobe.ssp.api.filter.AuthenticationFilter”。请确保该类包含在:您的\u-APP\WEB-INF\classes您的\u-APP\WEB-INF\lib

是的,我正在重写init()方法(请参考上面的筛选器类,现在编辑)。还有I@WebFilter(“/*”)但是同样的问题也存在。你能用导入和包名发布完整的过滤类吗?我已经编辑并添加了完整的过滤类,请看一看。另外,请帮助我了解此问题是否与多个上下文无关,以及我是否正确加载了这两个上下文(持久层上下文和服务层上下文)。您是否可以在生成路径导出库中查看依赖项导出的优先级?如果你能在那里放一个屏幕截图更好。是的,我正在重写init()方法(请参考上面的filter类,现在编辑)。还有我@WebFilter(“/*”),但存在相同的问题。你能用导入和包名发布完整的filter类吗?我已经编辑并添加了完整的filter类,请看一看。另外,请帮助我了解这个问题是否与多个上下文无关,并且我正在加载这两个上下文(持久层上下文和上下文)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">     
    <import resource="classpath:/applicationContext-data.xml" />
    <context:annotation-config />
    <context:component-scan base-package="com.app" />
    <context:property-placeholder location="classpath:*.properties" />
    <mvc:annotation-driven/>    
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd 
    http://www.springframework.org/schema/jdbc 
    http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd 
    http://www.springframework.org/schema/data/jpa 
    http://www.springframework.org/schema/data/jpa/spring-jpa-2.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- ************* JPA/Hibernate configuration ************* -->
    <bean 
        name="entityManagerFactory" 
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.app.data.*" />
        <property name="persistenceXmlLocation" value="classpath:persistence.xml" />
        <property name="persistenceUnitName" value="persistence-unit" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
    </bean>
    <bean 
        id="transactionManager" 
        class="org.springframework.orm.jpa.JpaTransactionManager" 
        p:entityManagerFactory-ref="entityManagerFactory" />

    <bean 
        id="dataSource" 
        class="org.apache.commons.dbcp.BasicDataSource"
        p:driverClassName="com.mysql.jdbc.Driver" 
        p:url="jdbc:mysql://localhost:3306/app"
        p:username="root" 
        p:password="root123" 
        p:initialSize="5"
        p:maxActive="10">
    </bean>
<context:component-scan base-package="com.app.data.*" />
    <tx:annotation-driven />
</beans>    
java.lang.ClassNotFoundException: com.adobe.ssp.api.filter.AuthenticationFilter