@ -1,133 +1,136 @@
/* */ package com.archive.framework.config
package com.archive.framework.config
;
/* */
/* */ import com.alibaba.druid.pool.DruidDataSource ;
/* */ import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder ;
/* */ import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties ;
/* */ import com.archive.common.utils.spring.SpringUtils ;
/* */ import com.archive.framework.aspectj.lang.enums.DataSourceType ;
/* */ import com.archive.framework.config.properties.DruidProperties ;
/* */ import com.archive.framework.datasource.DynamicDataSource ;
/* */ import java.util.HashMap ;
/* */ import java.util.Map ;
/* */ import javax.servlet.Filter ;
/* */ import javax.sql.DataSource ;
/* */ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty ;
/* */ import org.springframework.boot.context.properties.ConfigurationProperties ;
/* */ import org.springframework.boot.web.servlet.FilterRegistrationBean ;
/* */ import org.springframework.context.annotation.Bean ;
/* */ import org.springframework.context.annotation.Configuration ;
/* */ import org.springframework.context.annotation.Primary ;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ @Configuration
/* */ public class DruidConfig
/* */ {
/* */ @Bean
/* */ @ConfigurationProperties ( "spring.datasource.druid.master" )
/* */ public DataSource masterDataSource ( DruidProperties druidProperties ) {
/* 39 */ DruidDataSource dataSource = DruidDataSourceBuilder . create ( ) . build ( ) ;
/* 40 */ return ( DataSource ) druidProperties . dataSource ( dataSource ) ;
/* */ }
/* */
/* */
/* */ @Bean
/* */ @ConfigurationProperties ( "spring.datasource.druid.slave" )
/* */ @ConditionalOnProperty ( prefix = "spring.datasource.druid.slave" , name = { "enabled" } , havingValue = "true" )
/* */ public DataSource slaveDataSource ( DruidProperties druidProperties ) {
/* 48 */ DruidDataSource dataSource = DruidDataSourceBuilder . create ( ) . build ( ) ;
/* 49 */ return ( DataSource ) druidProperties . dataSource ( dataSource ) ;
/* */ }
/* */
/* */
/* */ @Bean ( name = { "dynamicDataSource" } )
/* */ @Primary
/* */ public DynamicDataSource dataSource ( DataSource masterDataSource ) {
/* 56 */ Map < Object , Object > targetDataSources = new HashMap < > ( ) ;
/* 57 */ targetDataSources . put ( DataSourceType . MASTER . name ( ) , masterDataSource ) ;
/* 58 */ setDataSource ( targetDataSources , DataSourceType . SLAVE . name ( ) , "slaveDataSource" ) ;
/* 59 */ return new DynamicDataSource ( masterDataSource , targetDataSources ) ;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void setDataSource ( Map < Object , Object > targetDataSources , String sourceName , String beanName ) {
/* */ try {
/* 73 */ DataSource dataSource = ( DataSource ) SpringUtils . getBean ( beanName ) ;
/* 74 */ targetDataSources . put ( sourceName , dataSource ) ;
/* */ }
/* 76 */ catch ( Exception exception ) { }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ @Bean
/* */ @ConditionalOnProperty ( name = { "spring.datasource.druid.statViewServlet.enabled" } , havingValue = "true" )
/* */ public FilterRegistrationBean removeDruidFilterRegistrationBean ( DruidStatProperties properties ) {
/* 90 */ DruidStatProperties . StatViewServlet config = properties . getStatViewServlet ( ) ;
/* */
/* 92 */ String pattern = ( config . getUrlPattern ( ) ! = null ) ? config . getUrlPattern ( ) : "/druid/*" ;
/* 93 */ String commonJsPattern = pattern . replaceAll ( "\\*" , "js/common.js" ) ;
/* 94 */ String filePath = "support/http/resources/js/common.js" ;
/* */
/* 96 */ Object object = new Object ( this ) ;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* 123 */ FilterRegistrationBean registrationBean = new FilterRegistrationBean ( ) ;
/* 124 */ registrationBean . setFilter ( ( Filter ) object ) ;
/* 125 */ registrationBean . addUrlPatterns ( new String [ ] { commonJsPattern } ) ;
/* 126 */ return registrationBean ;
/* */ }
/* */ }
import com.alibaba.druid.pool.DruidDataSource ;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder ;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties ;
import com.alibaba.druid.util.Utils ;
import com.archive.common.utils.spring.SpringUtils ;
import com.archive.framework.aspectj.lang.enums.DataSourceType ;
import com.archive.framework.config.properties.DruidProperties ;
import com.archive.framework.datasource.DynamicDataSource ;
import java.io.IOException ;
import java.util.HashMap ;
import java.util.Map ;
import javax.servlet.* ;
import javax.sql.DataSource ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty ;
import org.springframework.boot.context.properties.ConfigurationProperties ;
import org.springframework.boot.web.servlet.FilterRegistrationBean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Primary ;
@Configuration
public class DruidConfig
{
@Bean
@ConfigurationProperties ( "spring.datasource.druid.master" )
public DataSource masterDataSource ( DruidProperties druidProperties ) {
DruidDataSource dataSource = DruidDataSourceBuilder . create ( ) . build ( ) ;
return ( DataSource ) druidProperties . dataSource ( dataSource ) ;
}
@Bean
@ConfigurationProperties ( "spring.datasource.druid.slave" )
@ConditionalOnProperty ( prefix = "spring.datasource.druid.slave" , name = { "enabled" } , havingValue = "true" )
public DataSource slaveDataSource ( DruidProperties druidProperties ) {
DruidDataSource dataSource = DruidDataSourceBuilder . create ( ) . build ( ) ;
return ( DataSource ) druidProperties . dataSource ( dataSource ) ;
}
@Bean ( name = { "dynamicDataSource" } )
@Primary
public DynamicDataSource dataSource ( DataSource masterDataSource ) {
Map < Object , Object > targetDataSources = new HashMap < > ( ) ;
targetDataSources . put ( DataSourceType . MASTER . name ( ) , masterDataSource ) ;
setDataSource ( targetDataSources , DataSourceType . SLAVE . name ( ) , "slaveDataSource" ) ;
return new DynamicDataSource ( masterDataSource , targetDataSources ) ;
}
public void setDataSource ( Map < Object , Object > targetDataSources , String sourceName , String beanName ) {
try {
DataSource dataSource = ( DataSource ) SpringUtils . getBean ( beanName ) ;
targetDataSources . put ( sourceName , dataSource ) ;
}
catch ( Exception exception ) { }
}
@Bean
@ConditionalOnProperty ( name = { "spring.datasource.druid.statViewServlet.enabled" } , havingValue = "true" )
public FilterRegistrationBean removeDruidFilterRegistrationBean ( DruidStatProperties properties ) {
DruidStatProperties . StatViewServlet config = properties . getStatViewServlet ( ) ;
String pattern = ( config . getUrlPattern ( ) ! = null ) ? config . getUrlPattern ( ) : "/druid/*" ;
String commonJsPattern = pattern . replaceAll ( "\\*" , "js/common.js" ) ;
String filePath = "support/http/resources/js/common.js" ;
Filter filter = new Filter ( )
{
@Override
public void init ( javax . servlet . FilterConfig filterConfig ) throws ServletException
{
}
@Override
public void doFilter ( ServletRequest request , ServletResponse response , FilterChain chain )
throws IOException , ServletException
{
chain . doFilter ( request , response ) ;
// 重置缓冲区,响应头不会被重置
response . resetBuffer ( ) ;
// 获取common.js
String text = Utils . readFromResource ( filePath ) ;
// 正则替换banner, 除去底部的广告信息
text = text . replaceAll ( "<a.*?banner\"></a><br/>" , "" ) ;
text = text . replaceAll ( "powered.*?shrek.wang</a>" , "" ) ;
response . getWriter ( ) . write ( text ) ;
}
@Override
public void destroy ( )
{
}
} ;
FilterRegistrationBean registrationBean = new FilterRegistrationBean ( ) ;
registrationBean . setFilter ( filter ) ;
registrationBean . addUrlPatterns ( commonJsPattern ) ;
return registrationBean ;
}
}
/ * Location : C : \ Users \ Administrator \ Desktop \ extracted . zip ! \ extracted \ BOOT - INF \ classes \ com \ archive \ framework \ config \ DruidConfig . class