복붙노트

[SPRING] 봄 포함 된 부두 + cxf

SPRING

봄 포함 된 부두 + cxf

스프링 ioc 컨테이너 안에 묻힌 부두가 있습니다. 스프링 ioc에는 전체 구성을 (단일 JVM에서) 완벽하고 완벽한 웹 응용 프로그램 개발 환경으로 만드는 임베디드 hsqldb도 포함되어 있습니다. 이제 부두 호스트를 서블릿뿐만 아니라 웹 서비스로 만들기 위해이 환경에 아파치 CXF를 추가하려고합니다.

불행히도 http://127.0.0.1:8080/cxf/*에 액세스하려고 할 때 NullPointerException이 발생합니다 (서블릿과 정적 컨텐츠는 괜찮습니다). 어떤 생각이 잘못된거야?

2010-09-17 15:37:20,099 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - REQUEST /cxf/ on org.mortbay.jetty.HttpConnection@2d14d18f
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - servlet=cxf-servlet-holder
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - chain=null
2010-09-17 15:37:20,100 [btpool0-1 - /cxf/] DEBUG org.mortbay.log - servelet holder=cxf-servlet-holder
2010-09-17 15:37:20,101 [btpool0-1 - /cxf/] ERROR org.mortbay.log - /cxf/
java.lang.NullPointerException
    at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
    at org.mortbay.jetty.Server.handle(Server.java:281)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:502)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:821)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:208)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:378)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:368)
    at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)

나는 봄을 초기화하고있다 :

public static void main(String[] args) throws Exception {
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] { "jetty-beans.xml" , "cxf-beans.xml" });
    applicationContext.getBean("web-server", Server.class).join();
}

jetty-beans.xml :

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

    <bean name="web-server" class="org.mortbay.jetty.Server"
        init-method="start">
        <property name="connectors">
            <list>
                <bean class="org.mortbay.jetty.nio.SelectChannelConnector">
                    <property name="host" value="localhost" />
                    <property name="port" value="8080" />
                </bean>
            </list>
        </property>
        <property name="handlers">
            <list>
                <ref bean="web-server-context-static" />
                <ref bean="web-server-context-servlet" />
                <ref bean="web-server-context-cxf" />
            </list>
        </property>
    </bean>

    <bean name="web-server-context-static" class="org.mortbay.jetty.servlet.Context">
        <property name="contextPath" value="/static" />
        <property name="handler">
            <bean class="org.mortbay.jetty.handler.ResourceHandler">
                <property name="resourceBase" value="static" />
            </bean>
        </property>
    </bean>

    <bean name="web-server-context-servlet" class="org.mortbay.jetty.servlet.Context">
        <property name="contextPath" value="/servlet" />
        <property name="handler">
            <bean class="org.mortbay.jetty.servlet.ServletHandler">
                <property name="servlets">
                    <list>
                        <bean class="org.mortbay.jetty.servlet.ServletHolder">
                            <property name="name" value="servlet-holder" />
                            <property name="servlet">
                                <bean class="test.TestServlet" />
                            </property>
                        </bean>
                    </list>
                </property>
                <property name="servletMappings">
                    <list>
                        <bean class="org.mortbay.jetty.servlet.ServletMapping">
                            <property name="servletName" value="servlet-holder" />
                            <property name="pathSpec" value="/*" />
                        </bean>
                    </list>
                </property>
            </bean>
        </property>
    </bean>

    <bean name="web-server-context-cxf" class="org.mortbay.jetty.servlet.Context">
        <property name="contextPath" value="/cxf" />
        <property name="handler">
            <bean class="org.mortbay.jetty.servlet.ServletHandler">
                <property name="servlets">
                    <list>
                        <bean class="org.mortbay.jetty.servlet.ServletHolder">
                            <property name="name" value="cxf-servlet-holder" />
                            <property name="servlet">
                                <bean class="org.apache.cxf.transport.servlet.CXFServlet">
                                </bean>
                            </property>
                        </bean>
                    </list>
                </property>
                <property name="servletMappings">
                    <list>
                        <bean class="org.mortbay.jetty.servlet.ServletMapping">
                            <property name="servletName" value="cxf-servlet-holder" />
                            <property name="pathSpec" value="/*" />
                        </bean>
                    </list>
                </property>
            </bean>
        </property>
    </bean>

</beans>

cxf-beans.xml :

<?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:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <bean id="test-ws-impl" class="test.TestWSImpl" />

    <jaxws:endpoint id="test-ws-endpoint" implementor="#test-ws-impl"
        address="/testWS" />

</beans>

classpath :

activation-1.1.jar
commons-logging-1.1.1.jar
cxf-2.2.10.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.13.jar
jcl-over-slf4j-1.6.1.jar
jetty-6.1.3.jar
jetty-annotations-6.1.3.jar
jetty-util-6.1.3.jar
log4j-1.2.16.jar
neethi-2.0.4.jar
org.springframework.aop-3.0.3.RELEASE.jar
org.springframework.asm-3.0.3.RELEASE.jar
org.springframework.beans-3.0.3.RELEASE.jar
org.springframework.context-3.0.3.RELEASE.jar
org.springframework.context.support-3.0.3.RELEASE.jar
org.springframework.core-3.0.3.RELEASE.jar
org.springframework.expression-3.0.3.RELEASE.jar
servlet-api-2.5-6.1.3.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.5.jar

TestWSImpl.java:

package test;

import javax.jws.WebService;

@WebService(endpointInterface = "test.TestWSInterface")
public class TestWSImpl implements TestWSInterface {

    @Override
    public String doTest(String testSubject) {
        return "successfully tested:" + testSubject;
    }

}

TestWSInterface.java

package test;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface TestWSInterface {

    String doTest(@WebParam String testSubject);

}

해결법

  1. ==============================

    1.위의 구성이 잘못되었음을 알았습니다.

    위의 구성이 잘못되었음을 알았습니다.

    나는 WebApplicationContext를 사용하지 않았다. CXFServlet보다 먼저 초기화되어야한다. 간단한 해결책은 CXFServlet의 비 스프링 버전을 사용하는 것입니다. ApplicationContext가 필요하지 않습니다 (웹 서비스에 대한 별도의 ApplicationContext를 만들고 싶지는 않습니다. 그 사이에 공유 된 DataSource가 있어야하기 때문에 필요합니다). 초기화 (웹 서비스가 코드에 게시되어야 함).

    컨텍스트 문제를 해결 한 후 부티크 6.1이 서블릿 컨텍스트를 적절한 방식으로 초기화하지 않는다는 것을 알게되었습니다. 7.x로 업데이트 한 후 모든 것이 올바르게 작동합니다.

    커스텀 WebApplicationContext를 작성한 후 WebApplicationContext로 main / root ApplicationContext를 사용하여 CXFServlet의 스프링 버전을 약 6 줄의 접착제 코드와 함께 사용할 수있었습니다.

  2. from https://stackoverflow.com/questions/3736380/spring-embeded-jettycxf by cc-by-sa and MIT license