Akh*_*iar 2 java spring web-services
我有一个Spring MVC项目.我写了类似的代码
@Controller
@RequestMapping("CallBack")
@WebService(name = "NotificationToCP", targetNamespace = "http://SubscriptionEngine.ibm.com")
public class CallbackController {
@RequestMapping("")
@ResponseBody
@WebMethod(action = "notificationToCP")
@RequestWrapper(localName = "notificationToCP", targetNamespace = "http://SubscriptionEngine.ibm.com", className = "in.co.mobiz.airtelVAS.model.NotificationToCP_Type")
@ResponseWrapper(localName = "notificationToCPResponse", targetNamespace = "http://SubscriptionEngine.ibm.com", className = "in.co.mobiz.airtelVAS.model.NotificationToCPResponse")
public NotificationToCPResponse index(
@WebParam(name = "notificationRespDTO", targetNamespace = "") CPNotificationRespDTO notificationRespDTO) {
return new NotificationToCPResponse();
}
}
Run Code Online (Sandbox Code Playgroud)
我可以一起使用Spring MVC + Webservices吗?我想要的只是作为一个接受SOAP请求并处理它的控制器.网址需要/ CallBack.我仍然像新手一样迷茫.像上面的东西会工作吗 另外,我如何实现目标.
我不会将Spring MVC和SOAP webservice(JAX-WS)混合在一起,因为它们用于不同的目的.
更好的做法是将业务操作封装在服务类中,并使用MVC控制器和JAX-WS公开它.例如:
HelloService的
@Service
public class HelloService {
public String sayHello() {
return "hello world";
}
}
Run Code Online (Sandbox Code Playgroud)
HelloController具有通过自动装配注入的HelloService引用.这是标准的Spring MVC控制器,它调用服务并将结果作为模型传递给视图(例如:hello.jsp视图)
@Controller
@RequestMapping("/hello")
public class HelloController {
@Autowired private HelloService helloService;
@RequestMapping(method = RequestMethod.GET)
public String get(Model model) {
model.addAttribute("message", helloService.sayHello());
return "hello";
}
}
Run Code Online (Sandbox Code Playgroud)
JAX-WS端点也调用相同的服务.不同之处在于服务作为SOAP Web服务公开
@WebService(serviceName="HelloService")
public class HelloServiceEndpoint {
@Autowired private HelloService helloService;
@WebMethod
public String sayHello() {
return helloService.sayHello();
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,上述JAX-WS样式的Web服务无法保证自动在所有Spring部署上运行,尤其是在非Java EE环境(tomcat)上部署时.可能需要其他设置.
| 归档时间: |
|
| 查看次数: |
10195 次 |
| 最近记录: |