CONFIG FOLDER:
ActiveMQConfig
package com.mailshine.springbootstandaloneactivemq.config;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.core.JmsTemplate;
import javax.jms.ConnectionFactory;
import java.util.ArrayList;
import java.util.Arrays;
@Configuration
public class ActiveMQConfig {
@Value("${active-mq.broker-url}")
private String brokerUrl;
@Bean
public ConnectionFactory connectionFactory(){
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(brokerUrl);
activeMQConnectionFactory.setTrustedPackages(Arrays.asList("com.mailshine.springbootstandaloneactivemq"));
return activeMQConnectionFactory;
}
@Bean
public JmsTemplate jmsTemplate(){
JmsTemplate jmsTemplate = new JmsTemplate();
jmsTemplate.setConnectionFactory(connectionFactory());
jmsTemplate.setPubSubDomain(true); // enable for Pub Sub to topic. Not Required for Queue.
return jmsTemplate;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(){
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setPubSubDomain(true);
return factory;
}
}
-----------------------------
ApplicationConfig:
package com.mailshine.springbootstandaloneactivemq.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* The type Application config.
*/
@Configuration
public class ApplicationConfig {
/**
* The type Browser history config.
*/
@Configuration
public static class BrowserHistoryConfig implements WebMvcConfigurer{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
}
----------------------------
SwaggerConfig:
package com.mailshine.springbootstandaloneactivemq.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* The type Swagger config.
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
/**
* Api docket.
*
* @return the docket
*/
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.mailshine.springbootstandaloneactivemq.controller"))
.paths(PathSelectors.any())
.build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo(
"Demo SpringBoot",
"This Api is for demo purpose",
null,
null,
null, null , null
);
}
}
0 Comments