我想传达2个应用程序,在我的第一个应用程序中,我正在使用restTemplate向第二个应用程序发送通知,这就是为什么我需要在我的第二个应用程序中有一个Rest端点。 在第一个应用程序(发送通知的那个)中,这是我用来发送通知的方法:
public void setSomething() {
String operation = "I'm sending you the operation ID";
// URL to the SelectSystem App
System.out.println("Tryin to send something to selectsystem-view");
final String uri = "http://localhost:8080/from";
RestTemplate restTemplate = new RestTemplate() ;
if (operation != null) {
restTemplate.postForObject( uri,operation, String.class);
System.out.println("Send is done !!");
}
}
在我的第二个应用程序(接收者)中,这是接收通知的类:
@RestController
public class NotificationReceiver {
@RequestMapping(value = "/from", method = RequestMethod.POST)
public ResponseEntity<String> createEmployee(@RequestBody String greeting) {
if (greeting !=null) {
System.out.println("The result From the other App is :"+greeting);
}
return new ResponseEntity(HttpStatus.CREATED);
}
@RequestMapping(value = "/from",method = RequestMethod.GET)
public void greeting() {
System.out.println("testing the restController");
}
}
我遇到的问题是我无法从web.xml映射我的RestController,因为我已经有了JSF映射,这是jsf映射web.xml:
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>modules/index.xhtml</welcome-file>
</welcome-file-list>
知道如何映射我的RestController吗?