Posts

Showing posts with the label Spring

Spring Boot | Sample REST Application

Image
In this post we are going to write a Simple REST Application in Spring Boot. Spring Boot has inbuilt tomcat which makes an application start without the need to have any application/web server. Though we can always deploy applications in web servers too. For this tutorial we will be using Maven for dependency management. Step 1. Add all required Spring dependencies in your pom file We can use below sample pom file to start with or go to https://start.spring.io/ to kick start your spring boot application. Step 2. Spring starter class Spring Boot uses @SpringBootApplication to auto configure some of spring configuration. You can find more info on  SpringBoot details Step 3. Application Controller We will be using MVC pattern to separate our restful layer from the service layer.   In our REST service we use  @RestController  annotation. It is combination of @Controller and @ResponseBody annotations. We created CustomerController to return customer d...

Spring | Autowiring Qualifier

Spring provides @Qualifier annotation to refer correct bean while doing autowiring. Suppose we have interface IService which has two concrete implementation. When we try to Autowire IService object in any other class it will throw exception as there are two beans. Spring Qualifier is used in such situation to place object of correct implementation class to autowired object.   Now, above iservice object will hold object of IServiceImplTwo class.

Spring | JMS Listener via JmsListener annotation

Spring framework provides annotation based configuration for dependency injection. Normally, MessageListener  interface needs to be implemented in Queue/Topic receiver class for incoming messages. The overridden onMessage method in that class handle the incoming message. Spring provides below annotations to enable jms communication. @JmsListener  annotation can mark any method to handle message.  @EnableJms  annotation to detect and register  @JmsListener  methods for jms messages. Below is class to handle jms message. @JmsListener requires default jms container factory configuration. Add below lines in bean conf file for this. Please refer this post for conf file. Deploy war file to JBoss server and send sample message from Gems tool.