How can I access the ServletContext from within a JAX-WS web service?과 비슷하게 applicationContext에 쉽게 액세스 할 수 있습니까?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;
}
}
그렇다면 appContext.getBean ('myBean')을 말할 수 없다면 Spring 서비스와 어떻게 협력 할 수 있을까요? – pihentagy
setter 또는 생성자를 통해 삽입하십시오. 의존성 주입이란 "전화하지 말고 전화 할게." 객체가 필요한 것을 얻기 위해 앱 컨텍스트를 가질 필요는 없습니다. – duffymo
수 없습니다. 글래스 피시에서 웹 서비스를 테스트하면 새 웹 서비스가 만들어지고 구성되지 않습니다. -o이 정보를 얻으려면 하루 정도 걸리는 디버깅이었습니다. ( – pihentagy