web-dev-qa-db-ja.com

Spring Security NoClassDefFoundError

Springプロジェクトに取り組んでおり、SpringSecurityの使用法を学んでいます。プロジェクトは機能していましたが、突然、やめようと決心しました。誰かが理由についていくつかの光を当てることができますか?

WebInit.Java

package com.catalyst.Config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class WebInit implements WebApplicationInitializer
{
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException
    {
        Dynamic hServlet;
        AnnotationConfigWebApplicationContext hAnnoCTX;

        hAnnoCTX = new AnnotationConfigWebApplicationContext();
        hAnnoCTX.register(WebMVCConfig.class);
        hAnnoCTX.setServletContext(servletContext);
        hServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(hAnnoCTX));
        hServlet.addMapping("/");
        hServlet.setLoadOnStartup(1);
    }
}

WebMVCConfig.Java

package com.catalyst.Config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

@Configuration
@ComponentScan("com.catalyst")
@EnableWebMvc
public class WebMVCConfig extends WebMvcConfigurerAdapter
{
    @Bean
    public UrlBasedViewResolver setupViewResolver()
    {
        UrlBasedViewResolver hResolver;
        hResolver = new UrlBasedViewResolver();
        hResolver.setPrefix("/WEB-INF/JSP/");
        hResolver.setSuffix(".jsp");
        hResolver.setViewClass(JstlView.class);
        return(hResolver);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry hRegistry)
    {
        hRegistry.addResourceHandler("/Resources/**").addResourceLocations("/WEB-INF/Resources/*");
    }
}

SpringSecurity.Java

package com.catalyst.Config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SpringSecurity extends WebSecurityConfigurerAdapter
{
    
    @Override
    public void configure(WebSecurity web) throws Exception
    {
        web.ignoring().antMatchers("/", "/Error/**", "/Resources/**");
    }
    
    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        http
            .authorizeRequests()
            .anyRequest().authenticated()
            .and()
            .formLogin()
                .loginPage("/Login").and()
            .httpBasic();
    }
    
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        auth
            .inMemoryAuthentication()
            .withUser("user").password("password").roles("USER").and()
            .withUser("admin").password("password").roles("USER", "ADMIN");
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.Apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.Apache.org/POM/4.0.0 http://maven.Apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.catalyst</groupId>
    <artifactId>prjPersonal</artifactId>
    <version>1.0_Personal</version>
    <packaging>war</packaging>

    <name>prjPersonal</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- Versions -->
        <jstl.version>1.2</jstl.version>
        <mysql.version>5.1.35</mysql.version>
        <spring.version>4.0.1.RELEASE</spring.version>
        <hibernate.version>5.0.0.CR1</hibernate.version>
    </properties>
    
    <dependencies>
        
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.1.6.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.1.6.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.6.RELEASE</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
        
        <!-- JSTL -->
        <dependency>  
            <groupId>jstl</groupId>  
            <artifactId>jstl</artifactId>  
            <version>${jstl.version}</version>  
        </dependency>
        
        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        
        <!-- MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-Java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.Apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.Apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.Apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Tomcatエラー

HTTP Status 500 - Servlet.init() for servlet dispatcher threw exception
root cause:

Java.lang.NoClassDefFoundError: org/springframework/security/web/access/WebInvocationPrivilegeEvaluator
        Java.lang.Class.getDeclaredMethods0(Native Method)
        Java.lang.Class.privateGetDeclaredMethods(Class.Java:2701)
        Java.lang.Class.getDeclaredMethods(Class.Java:1975)
        org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.Java:467)
        org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.Java:451)
        org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.Java:512)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.Java:663)
        org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.Java:593)
        org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.Java:1396)
        org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.Java:382)
        org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.Java:353)
        org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.Java:463)
        org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.Java:1071)
        org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.Java:277)
        org.springframework.web.servlet.DispatcherServlet.initHandlerMappings(DispatcherServlet.Java:549)
        org.springframework.web.servlet.DispatcherServlet.initStrategies(DispatcherServlet.Java:463)
        org.springframework.web.servlet.DispatcherServlet.onRefresh(DispatcherServlet.Java:452)
        org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.Java:550)
        org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.Java:484)
        org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.Java:136)
        javax.servlet.GenericServlet.init(GenericServlet.Java:158)
        org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:502)
        org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:79)
        org.Apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.Java:617)
        org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:518)
        org.Apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.Java:1091)
        org.Apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.Java:668)
        org.Apache.Tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.Java:2463)
        org.Apache.Tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.Java:2452)
        Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
        Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
        org.Apache.Tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.Java:61)
        Java.lang.Thread.run(Thread.Java:745)
9
Nicholas Duncan

依存関係を追加する

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>

またはgradle

dependencies {  
  compile 'org.springframework.security:spring-security-web:4.0.1.RELEASE'
}
16
fedrbodr

このorg.springframework.securityspring-security-web4.0.1.RELEASEを追加してください

13
Ramzy

私にとって、私はこの依存関係を追加することによってそれを解決しました:

<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-messaging</artifactId>
        </dependency>
3
Mohammed Fathi

WebInvocationPrivilegeEvaluatorインターフェイスはに存在します

org.springframework.security.web.accessパッケージ

spring-security-web-5.0.4.RELEASE.jar

.m2フォルダーから既存のjarファイルを削除し、新しいビルドを作成します。

C:\ Users\user.m2\repository\org\springframework\security\spring-security-web\5.0.4.RELEASE

私はバージョン5を使用しました。、あなたの場合は4 .

私の場合はうまくいきました、私の問題は解決しました

0
Naveen Kocherla