는 방법에 액세스할 수 있습니 ApplicationContext 내에서 JAX-WS 웹 서비스입니까?

StackOverflow https://stackoverflow.com/questions/602319

문제

비슷 는 방법에 액세스할 수 있습니 ServletContext 내에서 JAX-WS 웹 서비스입니까?, 이스에 액세스하는 방법 applicationContext,보다 쉽게 이?

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.ServletContext;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

@WebService
public class MyWebService {
    // boilerplate code begins :(

    @Resource
    private WebServiceContext context;
    private WebApplicationContext webApplicationContext = null;

    /**
     * @return
     * @throws IllegalStateException
     */
    private WebApplicationContext getWebApplicationContext()
            throws IllegalStateException {
        if (webApplicationContext != null)
            return webApplicationContext;
        ServletContext servletContext =
                (ServletContext) context.getMessageContext().get(
                        MessageContext.SERVLET_CONTEXT);
        webApplicationContext =
                WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        return webApplicationContext;
    }
}
도움이 되었습니까?

해결책

나는 생각하지 않는 웹 서비스에 대해 알아야 또는 웹 servlet 상황 또는 그 응용 프로그램다.나는 보지 않는 이유를 알고 있습니다.안 그것은 훨씬 더 많은 수동입니까?을 주입해 필요한 것을 할 수 있도록합니다.서비스와의 상호 작용을 클라이언트에 기초해야한다는 계약에 정의된다.면 그것을 얻을 수있는 알 수 없는 값에서의 컨텍스트에 대한 몇 가지 종류,어떻게 클라이언트가 될 필요가 무엇인지 설정하거나 설정하는 방법은?

나는 더 이상 갈고 말하는 웹 서비스에 대한 래퍼 봄 서비스 인터페이스입니다.그것은 단지 하나 더 많은 선택이 가능한 방법을 노출됩니다.당신의 웹사 서비스는 조금 더 많은 것 보다 마샬 및 unmarshal XML 요청/응답체와 함께 협력하 봄 서비스입니다.

다른 팁

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;


@WebService( 
    endpointInterface = "Bla", 
    targetNamespace = "http://bla/v001", 
    wsdlLocation = "WEB-INF/wsdl/bla.wsdl",    
    serviceName = "BlaService",
    portName = "BlaPort")
public class BlaWs extends SpringBeanAutowiringSupport implements BlaPort {

  @Autowired
  @Qualifier("dao") 
  private Dao dao;
  ...
}

귀하의 웹 서비스 콩 확장 봄 콩.

나는 것을 설치하는 필터를 저장 ServletContext 기 전에 체인에서 ThreadLocal

에 따라 JavaDoc 에 대한 SpringBeanAutowiringSupport 클래스를 참조하십시오:http://docs.spring.io/autorepo/docs/spring-framework/3.0.x/api/org/springframework/web/context/support/SpringBeanAutowiringSupport.html

참고:의 끝에서 javadoc.

원래 질문이 있을 수도 있습,방법이 될 수 있는 이것을 구현해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top