繁体   English   中英

class 找不到 javax.servlet.Filter 文件

[英]class file for javax.servlet.Filter not found

我收到以下错误:

/WebSecurityConfig.java:[20,8] cannot access javax.servlet.Filter
[ERROR]   class file for javax.servlet.Filter not found

对于我的 WebSecurityConfig class

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    private MUserDetailsService mUserDetailsService;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(mUserDetailsService);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable().authorizeRequests()
                .antMatchers("/api/auth/*").permitAll()
                .antMatchers("/actuator/*").permitAll()
                .anyRequest().authenticated();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/swagger-ui/**", "/v3/api-docs/**");
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(daoAuthenticationProvider());
    }

    @Bean
    public DaoAuthenticationProvider daoAuthenticationProvider() {
        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
        provider.setPasswordEncoder(passwordEncoder());
        provider.setUserDetailsService(mUserDetailsService);
        return provider;
    }

    @Bean("authenticationManager")
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
}

我试图摆脱 javax 以支持雅加达。

我没有在依赖树中看到 javax 依赖项,所以我不确定这个错误是怎么出现的?

我正在使用 spring 启动版本 3.0.0 依赖树:

[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:3.0.0:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:3.0.0:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.9.9.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:3.0.0:compile
[INFO] |  |  +- com.zaxxer:HikariCP:jar:5.0.1:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:6.0.2:compile
[INFO] |  +- org.hibernate.orm:hibernate-core:jar:6.1.5.Final:compile
[INFO] |  |  +- jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
[INFO] |  |  +- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.5.0.Final:runtime
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:6.0.2.Final:runtime
[INFO] |  |  +- org.jboss:jandex:jar:2.4.2.Final:runtime
[INFO] |  |  +- com.fasterxml:classmate:jar:1.5.1:runtime
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.12.19:runtime
[INFO] |  |  +- org.glassfish.jaxb:jaxb-runtime:jar:4.0.1:runtime
[INFO] |  |  |  \- org.glassfish.jaxb:jaxb-core:jar:4.0.1:runtime
[INFO] |  |  |     +- org.eclipse.angus:angus-activation:jar:1.0.0:runtime
[INFO] |  |  |     +- org.glassfish.jaxb:txw2:jar:4.0.1:runtime
[INFO] |  |  |     \- com.sun.istack:istack-commons-runtime:jar:4.1.1:runtime
[INFO] |  |  +- jakarta.inject:jakarta.inject-api:jar:2.0.0:runtime
[INFO] |  |  \- org.antlr:antlr4-runtime:jar:4.10.1:runtime
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:3.0.0:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:3.0.0:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:6.0.2:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:6.0.2:compile
[INFO] |  |  +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:2.0.4:compile
[INFO] |  \- org.springframework:spring-aspects:jar:6.0.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.0.0:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:3.0.0:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:3.0.0:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:3.0.0:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:3.0.0:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.4.5:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.4.5:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.19.0:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.19.0:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:2.0.4:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.33:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:3.0.0:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.14.1:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.14.1:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.14.1:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.14.1:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.14.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.0.0:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.1:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:10.1.1:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:10.1.1:compile
[INFO] |  +- org.springframework:spring-web:jar:6.0.2:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:6.0.2:compile
[INFO] |     \- org.springframework:spring-expression:jar:6.0.2:compile
[INFO] +- org.springframework.session:spring-session-data-redis:jar:2.6.1:compile
[INFO] |  +- org.springframework.session:spring-session-core:jar:2.6.1:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:6.0.2:compile
[INFO] |  \- org.springframework.data:spring-data-redis:jar:3.0.0:compile
[INFO] |     +- org.springframework.data:spring-data-keyvalue:jar:3.0.0:compile
[INFO] |     +- org.springframework:spring-oxm:jar:6.0.2:compile
[INFO] |     \- org.springframework:spring-context-support:jar:6.0.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:3.0.0:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:3.0.0:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:3.0.0:compile
[INFO] |  +- io.micrometer:micrometer-observation:jar:1.10.2:compile
[INFO] |  |  \- io.micrometer:micrometer-commons:jar:1.10.2:compile
[INFO] |  \- io.micrometer:micrometer-core:jar:1.10.2:compile
[INFO] |     +- org.hdrhistogram:HdrHistogram:jar:2.1.12:runtime
[INFO] |     \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:3.0.0:compile
[INFO] |  +- org.springframework:spring-aop:jar:6.0.2:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:6.0.0:compile
[INFO] +- org.postgresql:postgresql:jar:42.5.1:runtime
[INFO] |  \- org.checkerframework:checker-qual:jar:3.5.0:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-data-redis:jar:3.0.0:compile
[INFO] +- com.google.code.gson:gson:jar:2.9.0:compile
[INFO] +- io.micrometer:micrometer-registry-prometheus:jar:1.10.2:compile
[INFO] |  \- io.prometheus:simpleclient_common:jar:0.16.0:compile
[INFO] |     \- io.prometheus:simpleclient:jar:0.16.0:compile
[INFO] |        +- io.prometheus:simpleclient_tracer_otel:jar:0.16.0:compile
[INFO] |        |  \- io.prometheus:simpleclient_tracer_common:jar:0.16.0:compile
[INFO] |        \- io.prometheus:simpleclient_tracer_otel_agent:jar:0.16.0:compile
[INFO] +- org.springframework.security:spring-security-config:jar:5.6.2:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:6.0.0:compile
[INFO] |  |  \- org.springframework.security:spring-security-crypto:jar:6.0.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:6.0.2:compile
[INFO] |  +- org.springframework:spring-context:jar:6.0.2:compile
[INFO] |  \- org.springframework:spring-core:jar:6.0.2:compile
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.9.1:test
[INFO] |  +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |  +- org.junit.platform:junit-platform-commons:jar:1.9.1:test
[INFO] |  \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.9.1:test
[INFO] |  \- org.junit.platform:junit-platform-engine:jar:1.9.1:test
[INFO] +- org.junit.platform:junit-platform-launcher:jar:1.9.1:test
[INFO] +- org.mockito:mockito-junit-jupiter:jar:4.8.1:test
[INFO] |  \- org.mockito:mockito-core:jar:4.8.1:test
[INFO] |     +- net.bytebuddy:byte-buddy-agent:jar:1.12.19:test
[INFO] |     \- org.objenesis:objenesis:jar:3.2:test
[INFO] +- org.projectlombok:lombok:jar:1.18.24:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.0.0:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:3.0.0:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.0.0:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.7.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.4.8:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:2.4.8:test
[INFO] |  |        \- org.ow2.asm:asm:jar:9.1:test
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:compile
[INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:2.1.0:compile
[INFO] |  +- org.assertj:assertj-core:jar:3.23.1:test
[INFO] |  +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] |  +- org.junit.jupiter:junit-jupiter:jar:5.9.1:test
[INFO] |  |  \- org.junit.jupiter:junit-jupiter-params:jar:5.9.1:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.1:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-test:jar:6.0.2:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.9.0:test
[INFO] +- com.h2database:h2:jar:2.1.214:test
[INFO] +- io.lettuce:lettuce-core:jar:6.1.8.RELEASE:compile
[INFO] |  +- io.netty:netty-common:jar:4.1.85.Final:compile
[INFO] |  +- io.netty:netty-handler:jar:4.1.85.Final:compile
[INFO] |  |  +- io.netty:netty-resolver:jar:4.1.85.Final:compile
[INFO] |  |  +- io.netty:netty-buffer:jar:4.1.85.Final:compile
[INFO] |  |  +- io.netty:netty-transport-native-unix-common:jar:4.1.85.Final:compile
[INFO] |  |  \- io.netty:netty-codec:jar:4.1.85.Final:compile
[INFO] |  +- io.netty:netty-transport:jar:4.1.85.Final:compile
[INFO] |  \- io.projectreactor:reactor-core:jar:3.5.0:compile
[INFO] |     \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
[INFO] +- org.springdoc:springdoc-openapi-ui:jar:1.6.9:compile
[INFO] |  +- org.springdoc:springdoc-openapi-webmvc-core:jar:1.6.9:compile
[INFO] |  +- org.webjars:swagger-ui:jar:4.11.1:compile
[INFO] |  +- org.webjars:webjars-locator-core:jar:0.52:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.14.1:compile
[INFO] |  \- io.github.classgraph:classgraph:jar:4.8.147:compile
[INFO] +- org.springdoc:springdoc-openapi-security:jar:1.6.9:compile
[INFO] |  \- org.springdoc:springdoc-openapi-common:jar:1.6.9:compile
[INFO] |     \- io.swagger.core.v3:swagger-core:jar:2.2.0:compile
[INFO] |        +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] |        +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.14.1:compile
[INFO] |        +- io.swagger.core.v3:swagger-annotations:jar:2.2.0:compile
[INFO] |        +- io.swagger.core.v3:swagger-models:jar:2.2.0:compile
[INFO] |        \- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
[INFO] +- junit:junit:jar:4.13.2:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:2.2:test
[INFO] +- org.springframework.security:spring-security-test:jar:6.0.0:test
[INFO] \- it.ozimov:embedded-redis:jar:0.7.2:test
[INFO]    +- com.google.guava:guava:jar:21.0:test
[INFO]    \- commons-io:commons-io:jar:2.5:test

pom.xml:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.9.0</version>
        </dependency>
        <!-- Micrometer Prometheus registry  -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>5.6.2</version>
        </dependency>

我看过关于 stackoverflow 的其他类似问题,但它们涉及添加 javax 依赖项。 是否可以改用雅加达?

博客spring boot 3.0.0-M1 博客中推荐将javax.servlet.filter导入更改为jakarta.servlet.filter 但同样很少有第三方库发布 Jakarta EE 兼容版本,因此并非所有 Spring Boot 2.x 功能都具有 Spring Boot 3.xx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM