【问题标题】:Issues with spring-security dependencies using Maven使用 Maven 的 spring-security 依赖项问题
【发布时间】:2018-01-22 05:37:57
【问题描述】:

我正在使用spring 框架来创建Web 应用程序,并使用maven 作为构建器。
为了与spring 的安全功能进行交互,我在我的pom.xml 中添加了两个不同的依赖项:

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

      <dependency>
           <groupId>org.springframework.security</groupId>
           <artifactId>spring-security-config</artifactId>
           <version>4.0.3.RELEASE</version>
      </dependency>

我命令maven到clean package并执行mvn spring-boot:run得到以下错误信息:

java.lang.IllegalAccessError: 试图从类 org.springframework.boot.bind 访问方法 org.springframework.core.convert.support.DefaultConversionService.addCollectionConverters(Lorg/springframework/core/convert/converter/ConverterRegistry;)V .RelaxedConversionService

从堆栈跟踪中,(添加在下面)我了解到错误以 main 函数开始,该函数位于 Program.java 文件中。
main 函数如下:

  public static void main(String[] args) {
        SpringApplication.run(Program.class, args);
}

注意事项和推测

我的pom.xml 文件是根据我在网上阅读的各种教程编译而成的,一旦我齐心协力,我就继续。

此外,我在 企业网络 后面工作,那里有一个本地存储库,因此某些依赖项可能不是最新的或可用的最新版本。 pom 中某处的版本可能不匹配,但我似乎无法追踪其中一个。

要(尝试)重新创建错误,请复制下面的 pom.xml 并添加 2 个依赖项。
如果无法重新创建,我只能假设其中一个包损坏或损坏(我在本地存储库中遇到过几次坏包)

补充一下,我对mavenspring 框架还很陌生,请指出您在pom.xml 或结构中看到的任何新手错误。

我的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>ssp</groupId>
<artifactId>sspserver</artifactId>
<version>1.0</version>

<packaging>jar</packaging>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>1.5.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
        <version>1.5.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.3</version>
    </dependency>

    <!-- Local jars -->

    <dependency>
        <groupId>SSPClient</groupId>
        <artifactId>SSPClient</artifactId>
        <scope>system</scope>
        <version>1.0.0</version>
        <systemPath>${basedir}\lib\SSPClient.jar</systemPath>
    </dependency>

    <dependency>
        <groupId>smp8</groupId>
        <artifactId>smp8</artifactId>
        <scope>system</scope>
        <version>1.0.0</version>
        <systemPath>${basedir}\lib\smp8.jar</systemPath>
    </dependency>

</dependencies>

<build>
    <finalName>sspserver</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.6.RELEASE</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

整个堆栈跟踪:

java.lang.IllegalAccessError: tried to access method org.springframework.core.convert.support.DefaultConversionService.addCollectionConverters(Lorg/springframework/core/convert/converter/ConverterRegistry;)V from class org.springframework.boot.bind.RelaxedConversionService
at org.springframework.boot.bind.RelaxedConversionService.<init>(RelaxedConversionService.java:52)
at org.springframework.boot.bind.RelaxedDataBinder.modifyProperties(RelaxedDataBinder.java:148)
at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:128)
at org.springframework.validation.DataBinder.bind(DataBinder.java:715)
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:272)
at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:240)
at org.springframework.boot.context.config.ConfigFileApplicationListener.bindToSpringApplication(ConfigFileApplicationListener.java:241)
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:197)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:182)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:168)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at cpssp.Program.main(Program.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

在此致谢

【问题讨论】:

    标签: spring maven spring-security pom.xml


    【解决方案1】:

    已解决

    问题是我试图将spring-security-*spring-boot 一起使用。 相反,我需要使用:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>1.5.6.RELEASE</version>
        </dependency>
    

    spring-boot兼容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2012-02-15
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多