在Spring Boot Soap Web服务项目

时间:2017-11-14 10:09:28

标签: spring maven spring-boot spring-security pom.xml

Collegues,我正在尝试将基本身份验证添加到我的SOAP WS(Spring Boot Ppoject)中。 POM像:

<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">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <artifactId>ws-signer</artifactId>
    <packaging>jar</packaging>
    <name>ws-signer</name>
    <version>1.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <project.build.sourceJre>1.8</project.build.sourceJre>
        <project.build.targetJre>1.8</project.build.targetJre>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- spring-boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>com.acap</groupId>
            <artifactId>doc-signer</artifactId>
            <version>1.0-RELEASE</version>
        </dependency>


        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.16</version>
        </dependency>


        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>




    </dependencies>


    <build>
        <plugins>
            <!-- spring-boot-maven-plugin -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
              <!--  <dependencies>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.6.RELEASE</version>
                    </dependency>
                </dependencies>-->
            </plugin>
            <!-- maven-jaxb2-plugin -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

正如我所说,我想在我的soap web服务中添加基本身份验证。 据我所知,我需要添加下一个依赖项:

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

但是,如果我添加此依赖项并调用mvn spring-boot:run而不是发生异常:

  

线程中的异常&#34; main&#34; java.lang.IllegalArgumentException:不能   实例化接口   org.springframework.boot.SpringApplicationRunListener:   org.springframework.boot.context.event.EventPublishingRunListener at   org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:413)     在   org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)     在   org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:378)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:291)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)     在   com.acap.DocSignerWsApplication.main(DocSignerWsApplication.java:16)   引起:org.springframework.beans.BeanInstantiationException:   无法实例化   [org.springframework.boot.context.event.EventPublishingRunListener]:   构造函数抛出异常;嵌套异常是   java.lang.NoSuchMethodError:   org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava /郎/对象;)Ljava /郎/对象;     在   org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)     在   org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:409)     ... 6更多引起:java.lang.NoSuchMethodError:   org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava /郎/对象;)Ljava /郎/对象;     在   org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:105)     在   org.springframework.boot.context.event.EventPublishingRunListener。(EventPublishingRunListener.java:56)     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native   方法)at   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)     在   org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)     ......还有7个

依赖树是:

-- maven-dependency-plugin:2.10:tree (default-cli) @ ws-signer ---
[INFO] org.springframework.boot:ws-signer:jar:1.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.springframework.boot:spring-boot-starter-web-services:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.8.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.5.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.8.RELEASE:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile
[INFO] |  |  |  |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:compile
[INFO] |  |  +- org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
[INFO] |  |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] |  |  +- org.springframework:spring-web:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-oxm:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework.ws:spring-ws-core:jar:2.4.0.RELEASE:compile
[INFO] |     \- org.springframework.ws:spring-xml:jar:2.4.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.8.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] |  |  +- net.minidev:json-smart:jar:2.2.1:test
[INFO] |  |  |  \- net.minidev:accessors-smart:jar:1.1:test
[INFO] |  |  |     \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- org.assertj:assertj-core:jar:2.6.0:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.3.12.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.5.8.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.8.RELEASE:compile
[INFO] +- com.acap:doc-signer:jar:1.0-RELEASE:compile
[INFO] +- com.github.ulisesbocchio:jasypt-spring-boot-starter:jar:1.16:compile
[INFO] |  \- com.github.ulisesbocchio:jasypt-spring-boot:jar:1.16:compile
[INFO] |     \- org.jasypt:jasypt:jar:1.9.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.3.12.RELEASE:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.5.6:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] \- commons-io:commons-io:jar:2.5:compile     

更新

我删除了

<dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

并添加了

   <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
                <version>1.5.8.RELEASE</version>
            </dependency>

比我重写发送邮件的@Component

更新2

更改依赖项的位置:

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

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
</dependency>

没有依赖树看起来像:

[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] \- commons-io:commons-io:jar:2.5:compile

Stacktrace(在spring-boot:run之后)

17:14:42.118 ERROR [restartedMain] o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.selectInvocableMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/lang/reflect/Method;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.acap.DocSignerWsApplication.main(DocSignerWsApplication.java:16)
    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)
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.selectInvocableMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/lang/reflect/Method;
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:248)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:214)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:184)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:127)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 21 common frames omitted

我会很乐意为您提供任何帮助。

更新 - 决定

我的问题在于pom文件中的依赖序列。 有必要提高<artifactId> spring-boot-starter-security </ artifactId>以上(它应该接近org.springframework.boot组ID的其他依赖项)。 我的案例中正确的POM文件应如下所示:

 <dependencies>

        <!-- spring-boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>


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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
          </dependency>


        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.16</version>
        </dependency>

         <!-- other dependecies -->

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>


    </dependencies>

1 个答案:

答案 0 :(得分:1)

在依赖树中 - 为什么spring-boot-starter-security-1.5.8 ..显示在commons-io下?

[INFO] +- commons-io:commons-io:jar:2.5:compile [INFO] 
    \- org.springframework.boot:spring-boot-starter-security:jar:1.‌​5.8.RELEASE:compile

所以POM中的问题是依赖序列。