6

我正在玩spring-boot,但遇到了问题。创建 RESTful Web 服务非常容易。但我无法使用 spring-boot 运行肥皂服务。

实际上我的项目有 spring-boot-starter-web 依赖项。

是否需要一个尚不存在的额外 sprint-boot-starter?

有哪些解决方法?如果我有 SOAP 服务的 web.xml,我可以在初始化过程中以某种方式包含它吗?我知道已经存在类似的问题,但它并没有解决我的问题,因为那里的问题是基于 spring-web。所以我认为我的问题在其他地方。

我的soap-webservice 的端点看起来像这样:

@Endpoint
public class MyEndpoint {


    @PayloadRoot(localPart = "myRequest", namespace = "my.ns")
    @ResponsePayload
    public TResponse logRequest(@RequestPayload final TRequest request) {
        //some code
    }
//more methods
}

端点在一个xml中很奇怪,它由spring-boot通过ImportResource注释加载。

所以我的入门课程如下所示:

@Configuration
@EnableAutoConfiguration
@ImportResource({ "classpath:/my/pack/app.xml" }) //soap-endpoint is configured here. 
public class Example {

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

端点的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:web-services="http://www.springframework.org/schema/web-services"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="my.pack.webservice.service.endpoint" />

    <mvc:annotation-driven />

    <bean id="task"
        class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"
        p:portTypeName="Task" p:locationUri="/taskService/" p:requestSuffix="-request"
        p:responseSuffix="-response">
        <property name="schema">
            <bean class="org.springframework.xml.xsd.SimpleXsdSchema" p:xsd="classpath:/task.xsd" />
        </property>
    </bean>

    <bean
        class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
    </bean>

    <bean id="messageReceiver"
        class="org.springframework.ws.soap.server.SoapMessageDispatcher">
        <property name="endpointAdapters">
            <list>
                <ref bean="defaultMethodEndpointAdapter" />
            </list>
        </property>
    </bean>


    <bean id="messageFactory"
        class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
        <property name="payloadCaching" value="true" />
    </bean>

    <bean id="defaultMethodEndpointAdapter"
        class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
        <property name="methodArgumentResolvers">
            <list>
                <ref bean="marshallingPayloadMethodProcessor" />
            </list>
        </property>
        <property name="methodReturnValueHandlers">
            <list>
                <ref bean="marshallingPayloadMethodProcessor" />
            </list>
        </property>
    </bean>

    <bean id="marshallingPayloadMethodProcessor"
        class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
        <constructor-arg ref="marshaller" />
        <constructor-arg ref="marshaller" />
    </bean>


    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
        p:contextPath="my.pack.task.schema.beans">
        <property name="contextPaths">
            <list>
                <value>my.pack.task.schema.beans</value>
            </list>
        </property>
    </bean>

    <bean id="taskEndpoint"
        class="my.pack.reporting.webservice.service.endpoint.TaskEndpoint">
        <property name="taskService" ref="taskDatastoreService" />
    </bean>

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="*.wsdl">task</prop>
            </props>
        </property>
        <property name="defaultHandler" ref="messageReceiver" />
    </bean>

</beans>

除此之外,如果我有错误的依赖项,我会附加 maven 依赖项树:

[INFO] [dependency:tree {execution: default-cli}]
[INFO] de.trao:spring-boot-tryout:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:0.5.0.M7:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:0.5.0.M7:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:0.5.0.M7:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:0.5.0.M7:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-starter-logging:jar:0.5.0.M7:compile
[INFO] |  |     +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] |  |     +- org.slf4j:jul-to-slf4j:jar:1.7.5:compile
[INFO] |  |     +- org.slf4j:log4j-over-slf4j:jar:1.7.5:compile
[INFO] |  |     \- ch.qos.logback:logback-classic:jar:1.0.13:compile
[INFO] |  |        \- ch.qos.logback:logback-core:jar:1.0.13:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:0.5.0.M7:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.47:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:7.0.47:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.0:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.3.0:compile
[INFO] |  +- org.springframework:spring-web:jar:4.0.0.RELEASE:compile
[INFO] |  |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.0.0.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-core:jar:4.0.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.0.0.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.0.0.RELEASE:compile
[INFO] +- my.pack:my-soap-serv:jar:0.0.1-SNAPSHOT:compile
[INFO] |  +- org.springframework:spring-context:jar:4.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-aspects:jar:4.0.0.RELEASE:compile
[INFO] |  |  +- org.aspectj:aspectjweaver:jar:1.7.4:compile (version managed from 1.8.0.M1)
[INFO] |  |  \- org.springframework:spring-context-support:jar:4.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-oxm:jar:4.0.0.RELEASE:compile
[INFO] |  +- org.springframework.ws:spring-ws-core:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- org.springframework.ws:spring-xml:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- wsdl4j:wsdl4j:jar:1.6.1:compile
[INFO] |  |  \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  +- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.6.5:compile
[INFO] |  +- my.pack:datastore:jar:0.0.1-SNAPSHOT:compile
[INFO] |  |  +- com.googlecode.genericdao:dao:jar:1.2.0:compile
[INFO] |  |  |  \- com.googlecode.genericdao:search:jar:1.2.0:compile
[INFO] |  |  +- com.googlecode.genericdao:search-jpa-hibernate:jar:1.2.0:compile
[INFO] |  |  |  \- com.googlecode.genericdao:search-hibernate:jar:1.2.0:compile
[INFO] |  |  +- org.hibernate:hibernate-entitymanager:jar:4.2.8.Final:compile
[INFO] |  |  |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] |  |  |  +- org.hibernate:hibernate-core:jar:4.2.8.Final:compile
[INFO] |  |  |  |  \- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  |  |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] |  |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] |  |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.0.0.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-tx:jar:4.0.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-jdbc:jar:4.0.0.RELEASE:compile
[INFO] |  |  \- com.google.guava:guava:jar:15.0:compile
[INFO] |  +- org.apache.ws.commons.axiom:axiom:jar:1.2.5:compile
[INFO] |  +- my.pack:shared:jar:0.0.1-SNAPSHOT:compile
[INFO] |  \- my.pack:common:jar:1.0.0-SNAPSHOT:compile
[INFO] |     +- com.typesafe:config:jar:1.0.2:compile
[INFO] |     +- org.slf4j:slf4j-api:jar:1.7.5:compile (version managed from 1.7.2)
[INFO] |     +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |     \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] +- com.h2database:h2:jar:1.3.174:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.mockito:mockito-core:jar:1.9.5:test
[INFO] |  \- org.objenesis:objenesis:jar:1.0:test
[INFO] \- org.hamcrest:hamcrest-library:jar:1.3:test

Spring Boot 启动日志:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::             (v0.5.0.M7)

2014-01-14 14:59:30.196  INFO 15210 --- [           main] my.pack.Example                         : Starting Example on mango with PID 15210 (/home/myuser/Code/test/spring-boot-tryout/target/spring-boot-tryout-0.0.1-SNAPSHOT.jar started by myuser)
2014-01-14 14:59:30.250  INFO 15210 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4d8f36ef: startup date [Tue Jan 14 14:59:30 CET 2014]; root of context hierarchy
2014-01-14 14:59:30.624  INFO 15210 --- [           main] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [my/pack/app.xml]
2014-01-14 14:59:30.750  INFO 15210 --- [           main] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [my/pack/subpack/application-context-persistence.xml]
2014-01-14 14:59:31.216  INFO 15210 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'org.springframework.transaction.config.internalTransactionAdvisor': replacing [Root bean: class [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration; factoryMethodName=transactionAdvisor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]]
2014-01-14 14:59:31.243  INFO 15210 --- [           main] a.ConfigurationClassBeanDefinitionReader : Skipping bean definition for [BeanMethod:name=transactionManager,declaringClass=org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration]: a definition for bean 'transactionManager' already exists. This top-level bean definition is considered as an override.
2014-01-14 14:59:31.244  INFO 15210 --- [           main] a.ConfigurationClassBeanDefinitionReader : Skipping bean definition for [BeanMethod:name=entityManagerFactory,declaringClass=org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration]: a definition for bean 'entityManagerFactory' already exists. This top-level bean definition is considered as an override.
2014-01-14 14:59:31.504  WARN 15210 --- [           main] my.pack.common.config.AppSettings       : ConfigFilePath is blank, using default configuration
2014-01-14 14:59:31.587  INFO 15210 --- [           main] my.pack.common.config.ConfigValidator   : Beginning to validate the configuration
2014-01-14 14:59:31.710  INFO 15210 --- [           main] my.pack.common.config.ConfigValidator   : Validating finished
2014-01-14 14:59:31.913  INFO 15210 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerByCGLIB$$a83839b9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-01-14 14:59:31.972  INFO 15210 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-01-14 14:59:31.990  INFO 15210 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-01-14 14:59:32.007  INFO 15210 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-01-14 14:59:32.302  INFO 15210 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 9001
2014-01-14 14:59:32.539  INFO 15210 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2014-01-14 14:59:32.539  INFO 15210 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.47
2014-01-14 14:59:32.630  INFO 15210 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-01-14 14:59:32.630  INFO 15210 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2384 ms
2014-01-14 14:59:41.357  INFO 15210 --- [ost-startStop-1] o.a.catalina.util.SessionIdGenerator     : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [7,997] milliseconds.
2014-01-14 14:59:41.376  INFO 15210 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2014-01-14 14:59:41.376  INFO 15210 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2014-01-14 14:59:41.537  INFO 15210 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-01-14 14:59:41.782  INFO 15210 --- [ost-startStop-1] o.s.j.d.DriverManagerDataSource          : Loaded JDBC driver: org.h2.Driver
2014-01-14 14:59:41.851  INFO 15210 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'reporting'
2014-01-14 14:59:42.107  INFO 15210 --- [ost-startStop-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
2014-01-14 14:59:42.124  INFO 15210 --- [ost-startStop-1] org.hibernate.Version                    : HHH000412: Hibernate Core {4.2.8.Final}
2014-01-14 14:59:42.131  INFO 15210 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2014-01-14 14:59:42.134  INFO 15210 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2014-01-14 14:59:42.179  INFO 15210 --- [ost-startStop-1] org.hibernate.ejb.Ejb3Configuration      : HHH000204: Processing PersistenceUnitInfo [
    name: reporting
    ...]
2014-01-14 14:59:42.421  INFO 15210 --- [ost-startStop-1] o.h.s.j.c.i.ConnectionProviderInitiator  : HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
2014-01-14 14:59:42.731  INFO 15210 --- [ost-startStop-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2014-01-14 14:59:43.016  INFO 15210 --- [ost-startStop-1] o.h.e.t.i.TransactionFactoryInitiator    : HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
2014-01-14 14:59:43.025  INFO 15210 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2014-01-14 14:59:43.415  INFO 15210 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
Hibernate: alter table report drop constraint FK_5ld65a9c14kdtwywxr6262vdl
2014-01-14 14:59:43.421 ERROR 15210 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table report drop constraint FK_5ld65a9c14kdtwywxr6262vdl
2014-01-14 14:59:43.422 ERROR 15210 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : Tabelle "REPORT" nicht gefunden
Table "REPORT" not found; SQL statement:
alter table report drop constraint FK_5ld65a9c14kdtwywxr6262vdl [42102-174]
Hibernate: alter table task drop constraint FK_o2by8kw6mmcb95r8eq3jx074e
2014-01-14 14:59:43.422 ERROR 15210 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table task drop constraint FK_o2by8kw6mmcb95r8eq3jx074e
2014-01-14 14:59:43.422 ERROR 15210 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : Tabelle "TASK" nicht gefunden
Table "TASK" not found; SQL statement:
alter table task drop constraint FK_o2by8kw6mmcb95r8eq3jx074e [42102-174]
Hibernate: drop table customer if exists
Hibernate: drop table report if exists
Hibernate: drop table task if exists
Hibernate: create table customer (id bigint generated by default as identity, identifier varchar(255) not null, primary key (id))
Hibernate: create table report (id bigint generated by default as identity, description varchar(255), occurred bigint not null, resolved bigint not null, status integer not null, customer_id bigint not null, primary key (id))
Hibernate: create table task (id bigint generated by default as identity, description varchar(255), finished bigint, started bigint, status integer not null, customer_id bigint not null, primary key (id))
Hibernate: alter table customer add constraint UK_nonbx33y5nkpeeohhjs6r18c0 unique (identifier)
Hibernate: alter table report add constraint FK_5ld65a9c14kdtwywxr6262vdl foreign key (customer_id) references customer
Hibernate: alter table task add constraint FK_o2by8kw6mmcb95r8eq3jx074e foreign key (customer_id) references customer
2014-01-14 14:59:43.863  INFO 15210 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2014-01-14 14:59:44.141  INFO 15210 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-01-14 14:59:44.141  INFO 15210 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-01-14 14:59:44.344  INFO 15210 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 2967 ms
2014-01-14 14:59:44.858  INFO 15210 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-01-14 14:59:44.949  INFO 15210 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port: 9001
2014-01-14 14:59:44.950  INFO 15210 --- [           main] my.pack.Example                         : Started Example in 15.343 seconds (JVM running for 15.914)

感谢您的帮助

更新:我实际使用的代码就像一个魅力,你可以在这里查看: https ://github.com/Zarathustra616/spring-boot-ws-rest-example

4

1 回答 1

0

Spring WS 不需要MessageDispatcherServlet吗?所以你需要DispatcherServlet用其中之一替换默认值,例如

@Bean
public MessageDispatcherServlet dispatcherServlet() {
    return new MessageDispatcherServlet();
}
于 2014-01-14T15:48:18.863 回答