@ -1,133 +1,136 @@
/* */ package com.archive.framework.config
package com.archive.framework.config
;
;
/* */
/* */ import com.alibaba.druid.pool.DruidDataSource ;
import com.alibaba.druid.pool.DruidDataSource ;
/* */ import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder ;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder ;
/* */ import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties ;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties ;
/* */ import com.archive.common.utils.spring.SpringUtils ;
import com.alibaba.druid.util.Utils ;
/* */ import com.archive.framework.aspectj.lang.enums.DataSourceType ;
import com.archive.common.utils.spring.SpringUtils ;
/* */ import com.archive.framework.config.properties.DruidProperties ;
import com.archive.framework.aspectj.lang.enums.DataSourceType ;
/* */ import com.archive.framework.datasource.DynamicDataSource ;
import com.archive.framework.config.properties.DruidProperties ;
/* */ import java.util.HashMap ;
import com.archive.framework.datasource.DynamicDataSource ;
/* */ import java.util.Map ;
/* */ import javax.servlet.Filter ;
import java.io.IOException ;
/* */ import javax.sql.DataSource ;
import java.util.HashMap ;
/* */ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty ;
import java.util.Map ;
/* */ import org.springframework.boot.context.properties.ConfigurationProperties ;
import javax.servlet.* ;
/* */ import org.springframework.boot.web.servlet.FilterRegistrationBean ;
import javax.sql.DataSource ;
/* */ import org.springframework.context.annotation.Bean ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty ;
/* */ import org.springframework.context.annotation.Configuration ;
import org.springframework.boot.context.properties.ConfigurationProperties ;
/* */ import org.springframework.context.annotation.Primary ;
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
@Configuration
/* */ @ConfigurationProperties ( "spring.datasource.druid.master" )
public class DruidConfig
/* */ public DataSource masterDataSource ( DruidProperties druidProperties ) {
{
/* 39 */ DruidDataSource dataSource = DruidDataSourceBuilder . create ( ) . build ( ) ;
@Bean
/* 40 */ return ( DataSource ) druidProperties . dataSource ( dataSource ) ;
@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 ) {
@Bean
/* 48 */ DruidDataSource dataSource = DruidDataSourceBuilder . create ( ) . build ( ) ;
@ConfigurationProperties ( "spring.datasource.druid.slave" )
/* 49 */ return ( DataSource ) druidProperties . dataSource ( dataSource ) ;
@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 ) {
/* 56 */ Map < Object , Object > targetDataSources = new HashMap < > ( ) ;
@Bean ( name = { "dynamicDataSource" } )
/* 57 */ targetDataSources . put ( DataSourceType . MASTER . name ( ) , masterDataSource ) ;
@Primary
/* 58 */ setDataSource ( targetDataSources , DataSourceType . SLAVE . name ( ) , "slaveDataSource" ) ;
public DynamicDataSource dataSource ( DataSource masterDataSource ) {
/* 59 */ return new DynamicDataSource ( masterDataSource , targetDataSources ) ;
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 {
/* 73 */ DataSource dataSource = ( DataSource ) SpringUtils . getBean ( beanName ) ;
/* 74 */ targetDataSources . put ( sourceName , dataSource ) ;
public void setDataSource ( Map < Object , Object > targetDataSources , String sourceName , String beanName ) {
/* */ }
try {
/* 76 */ catch ( Exception exception ) { }
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 ) {
/* 90 */ DruidStatProperties . StatViewServlet config = properties . getStatViewServlet ( ) ;
@Bean
/* */
@ConditionalOnProperty ( name = { "spring.datasource.druid.statViewServlet.enabled" } , havingValue = "true" )
/* 92 */ String pattern = ( config . getUrlPattern ( ) ! = null ) ? config . getUrlPattern ( ) : "/druid/*" ;
public FilterRegistrationBean removeDruidFilterRegistrationBean ( DruidStatProperties properties ) {
/* 93 */ String commonJsPattern = pattern . replaceAll ( "\\*" , "js/common.js" ) ;
DruidStatProperties . StatViewServlet config = properties . getStatViewServlet ( ) ;
/* 94 */ String filePath = "support/http/resources/js/common.js" ;
/* */
String pattern = ( config . getUrlPattern ( ) ! = null ) ? config . getUrlPattern ( ) : "/druid/*" ;
/* 96 */ Object object = new Object ( this ) ;
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 ( )
/* 123 */ FilterRegistrationBean registrationBean = new FilterRegistrationBean ( ) ;
{
/* 124 */ registrationBean . setFilter ( ( Filter ) object ) ;
}
/* 125 */ registrationBean . addUrlPatterns ( new String [ ] { commonJsPattern } ) ;
} ;
/* 126 */ return registrationBean ;
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
/ * Location : C : \ Users \ Administrator \ Desktop \ extracted . zip ! \ extracted \ BOOT - INF \ classes \ com \ archive \ framework \ config \ DruidConfig . class