This is a kind of "what is @Service annotation?" question, but with another approach. Because, I am not sure what is going on here:
I have a controller class:
@Controller
public class GreetingController {
@Autowired
SomeBean someBean;
@MessageMapping("/msg")
public String msg() {
someBean.handleMsg();
return "";
}
}
From within someBean.handleMsg
I try to send a response to a destination.
Some thing like this:
public class SomeBean {
@Autowired
private SimpMessagingTemplate messagingTemplate;
public handleMsg() {
messagingTemplate.convertAndSend("/topic/someTopic", "Response");
}
}
There are two versions of configuration.
- SomeBean is configured in .xml:
Like:
< bean id="someBean" class="package.SomeBean"></bean>
- SomeBean is annotated as service (in the first one it does not have):
Like:
@Service
public class SomeBean{...}
- Please note that in these two cases there is not any problem about injections etc. In both cases the client is successfully subscribed, sent message, and message is handled.
The only difference is:
- When
SomeBean
has@Service
annotation, it successfully responses to the client, but when it does NOT have, the client does not receive the response message, although there is not any exception.
Here is the question:
- What actually does @Service in this case? Could someone please explain what is going on here?