使用Maven的spring-security依赖项问题

时间:2017-08-14 11:29:30

标签: spring maven spring-security pom.xml

我正在使用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;) .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)

先谢谢

1 个答案:

答案 0 :(得分:0)

解决

问题在于我尝试将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兼容。