【问题标题】:How to migrate from SOAP CXF web.xml config to Spring-Boot?如何从 SOAP CXF web.xml 配置迁移到 Spring-Boot?
【发布时间】:2014-09-02 08:19:15
【问题描述】:

我想将现有的 web.xml 配置迁移到 spring-boot

但是如何正确地做到这一点呢?

这是 web.xml:

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/applicationContext.xml</param-value>
    </context-param>
 <servlet>
    <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/soap/*</url-pattern>
    </servlet-mapping>

如何将其转换为基于注释的 spring-boot 配置?我尝试了以下方法:

@Configuration
@EnableAutoConfiguration
public class AppConfig extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AppConfig.class);
    }


    @Bean
    public CXFServlet cxf() {
        return new CXFServlet();
    }   
}

但是在tomcat上启动时,抛出如下异常:

Caused by: java.lang.NullPointerException: null
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.destroy(CXFNonSpringServlet.java:184)
    at org.apache.cxf.transport.servlet.CXFServlet.onApplicationEvent(CXFServlet.java:166)
    at org.apache.cxf.transport.servlet.CXFServlet.onApplicationEvent(CXFServlet.java:41)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:776)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:142)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:130)
    at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:89)
    at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:51)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5444)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

【问题讨论】:

    标签: spring soap cxf spring-boot


    【解决方案1】:

    您应该将ServletRegistrationBean 用于CXFServlet。这将确保它已注册到 servlet 容器并允许您配置 URL 模式等。例如:

    @Bean
    public ServletRegistrationBean cxf() {
        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
    }
    

    【讨论】:

      猜你喜欢
      • 2015-04-10
      • 1970-01-01
      • 2014-04-18
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 2018-08-12
      • 2013-12-13
      相关资源
      最近更新 更多