parent
df6c502b6c
commit
c184e2dd4e
@ -1,36 +0,0 @@
|
|||||||
package com.imitate.common.config;
|
|
||||||
|
|
||||||
import com.imitate.common.util.RedisPool;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|
||||||
import org.springframework.context.ApplicationListener;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class InitListener implements ApplicationListener<ApplicationReadyEvent> {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(InitListener.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(ApplicationReadyEvent event) {
|
|
||||||
String active = System.getProperty("spring.profiles.active");
|
|
||||||
// 本地不初始化这些信息
|
|
||||||
Jedis jedis = null;
|
|
||||||
try {
|
|
||||||
if (!StringUtils.equals(active, "local")) {
|
|
||||||
// 初始化redis
|
|
||||||
jedis = RedisPool.getJedis();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("项目启动失败", e);
|
|
||||||
if ("jedisPool初始化错误".equals(e.getMessage())) {
|
|
||||||
Runtime.getRuntime().exit(-1);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
RedisPool.returnResource(jedis);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package com.imitate.common.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
||||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|
||||||
|
|
||||||
@Order(1)
|
|
||||||
@Configuration
|
|
||||||
public class RedisListenerConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
RedisMessageListenerContainer listenerContainer(RedisConnectionFactory connectionFactory) {
|
|
||||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
|
||||||
container.setConnectionFactory(connectionFactory);
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.imitate.web.init;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.service.ApiKey;
|
||||||
|
import springfox.documentation.service.AuthorizationScope;
|
||||||
|
import springfox.documentation.service.SecurityReference;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author tanzf
|
||||||
|
* @Description
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableSwagger2
|
||||||
|
public class SwaggerConfig extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("swagger-ui.html")
|
||||||
|
.addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
registry.addResourceHandler("/webjars/**")
|
||||||
|
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket createRestApi() {
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.apiInfo(apiInfo())
|
||||||
|
.select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("com.imitate.web"))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目信息
|
||||||
|
*/
|
||||||
|
private ApiInfo apiInfo() {
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title("Swagger测试项目 RESTful APIs")
|
||||||
|
.version("1.0")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue