Spring-从xml到Java配置
我从Spring的项目中得到了web.xml和applicationContext.xml。 我想改变这一点,只为我的项目获取Java配置,但我不知道如何实现 web xmlSpring-从xml到Java配置,java,xml,spring,spring-mvc,Java,Xml,Spring,Spring Mvc,我从Spring的项目中得到了web.xml和applicationContext.xml。 我想改变这一点,只为我的项目获取Java配置,但我不知道如何实现 web xml Spring+JAX-WS JAXWSservlet com.sun.xml.ws.transport.http.servlet.WSSpringServlet JAXWSservlet /你好 org.springframework.web.context.ContextLoaderListener applicat
Spring+JAX-WS
JAXWSservlet
com.sun.xml.ws.transport.http.servlet.WSSpringServlet
JAXWSservlet
/你好
org.springframework.web.context.ContextLoaderListener
applicationContext.xml
谢谢你的建议 Spring为JAX-WSServlet端点实现提供了一个方便的基类-
SpringBeanAutowiringSupport
。为了公开我们的HelloService
,我们扩展了Spring的SpringBeanAutowiringSupport
类,并在这里实现我们的业务逻辑,通常将调用委托给业务层。我们将简单地使用Spring的@Autowired
注释来表达对Spring托管bean的依赖
@WebService(serviceName="hello")
public class HelloServiceEndpoint extends SpringBeanAutowiringSupport {
@Autowired
private HelloService service;
@WebMethod
public void helloWs() {
service.hello();
}
}
服务本身:
public class HelloService {
public void hello() {
// impl
}
}
和配置
@Configuration
public class JaxWsConfig {
@Bean
public ServletRegistrationBean wsSpringServlet() {
return new ServletRegistrationBean(new WSSpringServlet(), "/api/v10");
}
@Bean
public HelloService helloService() {
return new HelloService();
}
}
可能是重复的,希望中的编辑有帮助。谢谢评论。所以我可以使用这两个类而不是xml配置文件?是的,您还需要将配置添加到您的应用程序中。我找不到WSSpringServlet(),我在SpringBoot 1.3.3上,请将以下依赖项添加到您的项目中。@MikeShauneu如果我不能使用WSSpringServlet怎么办?
public class HelloService {
public void hello() {
// impl
}
}
@Configuration
public class JaxWsConfig {
@Bean
public ServletRegistrationBean wsSpringServlet() {
return new ServletRegistrationBean(new WSSpringServlet(), "/api/v10");
}
@Bean
public HelloService helloService() {
return new HelloService();
}
}