@Bean
@ConditionalOnClass(
name = {"org.springframework.security.core.session.SessionRegistry"}
)
@Configuration
@ConditionalOnProperty(
prefix = "redis.session",
value = {"enable-redis-session"},
havingValue = "true"
)
@EnableConfigurationProperties({RedisSessionCustomConfig.class})
Resource[]=new org.springframework.core.io.support.ResourcePatternResolver.getResources("classpath*:" + path + "/**/*.class")
@Bean
@ConditionalOnMissingBean({IMuiltiDataSourcesConfig.class})
public IMuiltiDataSourcesConfig muiltiDataSourcesConfig() {
MuiltiDataSourcesConfig mdsc = new MuiltiDataSourcesConfig();
return mdsc;
}
@ConditionalOnMissingBean(
name = {"gavinTransactionManager"}
)
public PlatformTransactionManager transactionManager(List<DataSource> dataSources) {
List<DataSourceTransactionManager> tranManagers = new ArrayList();
dataSources = (List)dataSources.stream().distinct().collect(Collectors.toList());
Iterator var3 = dataSources.iterator();
while(var3.hasNext()) {
DataSource ds = (DataSource)var3.next();
DataSourceTransactionManager tran = new DataSourceTransactionManager(ds);
tranManagers.add(tran);
}
ChainedTransactionManager chainedTransactionManager = new ChainedTransactionManager((PlatformTransactionManager[])tranManagers.toArray(new PlatformTransactionManager[0]));
return chainedTransactionManager;
}
@Bean
public StatFilter statFilter() {
StatFilter statFilter = new StatFilter();
statFilter.setMergeSql(true);
statFilter.setSlowSqlMillis(5000L);
statFilter.setLogSlowSql(true);
return statFilter;
获取spring里边全局的bean
public class ConfigUtil implements ApplicationContextAware {
public static ApplicationContext applicationContext;
public static IdGenerator idgen;
public ConfigUtil() {
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
applicationContext = applicationContext;
idgen = (IdGenerator)applicationContext.getBean("idGenerator");
}
public static String nextId() throws Exception {
if (idgen == null) {
throw new Exception("IoC未初始化完成,请待初始化完成后调用。");
} else {
return String.valueOf(idgen.nextId());
}
}
}
@Bean
public Slf4jLogFilter logFilter() {
Slf4jLogFilter logFilter = new Slf4jLogFilter();
logFilter.setConnectionLogEnabled(false);
logFilter.setStatementLogEnabled(true);
logFilter.setResultSetLogEnabled(true);
logFilter.setStatementExecutableSqlLogEnable(true);
return logFilter;
}
@Bean
public ServletRegistrationBean druidServlet() {
ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings(new String[]{"/druid/*"});
reg.setEnabled(this.mybatisCustomerConfig.getStateViewEnabled());
reg.addInitParameter("loginUsername", this.mybatisCustomerConfig.getStatViewUserName());
reg.addInitParameter("loginPassword", this.mybatisCustomerConfig.getStatViewPassword());
reg.addInitParameter("logSlowSql", "true");
return reg;
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns(new String[]{"/*"});
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
filterRegistrationBean.addInitParameter("profileEnable", "true");
return filterRegistrationBean;
}
com.alibaba.ttl.TransmittableThreadLocal代替threadlocal