Skip to content

Commit

Permalink
version upgrade
Browse files Browse the repository at this point in the history
1.0.31.01
append  druid servlet auto config
  • Loading branch information
cuisongliu committed May 18, 2017
1 parent 279fb29 commit 5aafd81
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ at application.properties or application.yml append some properties.
|spring.datasource.druid.validation-query-timeout|yes|-1|
|spring.datasource.druid.min-evictable-idle-time-millis|yes|1000L * 60L * 30L|
|spring.datasource.druid.connection-properties|yes|null|
|spring.datasource.druid.servlet.enabled|yes|true|
|spring.datasource.druid.servlet.url-mappings|yes|/druid/*|
|spring.datasource.druid.servlet.allow|yes|null|
|spring.datasource.druid.servlet.deny|yes|null|
|spring.datasource.druid.servlet.login-username|yes|null|
|spring.datasource.druid.servlet.login-password|yes|null|
|spring.datasource.druid.servlet.reset-enable|yes|null|




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import javax.sql.DataSource;
import java.sql.SQLException;
Expand All @@ -41,6 +42,7 @@
@Configuration
@EnableConfigurationProperties(DruidProperties.class)
@ConditionalOnClass(DruidDataSource.class)
@Import({DruidServletAutoConfiguration.class})
public class DruidAutoConfiguration {


Expand Down Expand Up @@ -92,7 +94,7 @@ private void configDruid(DruidDataSource dataSource, DruidProperties properties)
dataSource.setPoolPreparedStatements(properties.getPoolPreparedStatements());
dataSource.setConnectProperties(properties.getConnectionProperties());
try {
dataSource.setFilters(properties.getFilters() != null ? properties.getFilters() : "stat");
dataSource.setFilters(properties.getFilters());
} catch (SQLException e) {
throw new IllegalArgumentException("please check your spring.datasource.druid.filters property.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.Properties;

/**
* 只提供了常用的属性,如果有需要,自己添加
* druid数据源的基础属性
*
* @author cuijinrui
* @since 2017/5/14
Expand All @@ -52,7 +52,7 @@ public class DruidProperties {
//# 打开PSCache,并且指定每个连接上PSCache的大小
private Boolean poolPreparedStatements = false;
//配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
private String filters = "";
private String filters = "stat";
private Integer maxPoolPreparedStatementPerConnectionSize = -1;
private Integer validationQueryTimeout = -1;
private Long minEvictableIdleTimeMillis = DruidAbstractDataSource.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 cuisongliu@qq.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cuisongliu.druid.autoconfigure;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;


/**
* druid servlet auto config
* @author cuisongliu
* @since 2017/5/18
*/
@EnableConfigurationProperties(DruidServletProperties.class)
@ConditionalOnProperty(name = "spring.datasource.druid.servlet.enabled", havingValue = "true", matchIfMissing = true)
public class DruidServletAutoConfiguration {

@Bean
@ConfigurationProperties(DruidServletProperties.DRUID_SERVLET_PREFIX)
public ServletRegistrationBean druidServlet(DruidServletProperties properties) {
ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings(properties.getUrlMappings());
if(properties.getAllow() !=null){
reg.addInitParameter("allow", properties.getAllow()); // IP白名单 (没有配置或者为空,则允许所有访问)
}
if(properties.getDeny() !=null){
reg.addInitParameter("deny", properties.getDeny()); //IP黑名单 (存在共同时,deny优先于allow)
}
if(properties.getLoginUsername() !=null){
reg.addInitParameter("loginUsername", properties.getLoginUsername()); //用户名
}
if(properties.getLoginPassword() !=null){
reg.addInitParameter("loginPassword", properties.getLoginPassword()); // 密码
}
if(properties.getResetEnable() !=null){
reg.addInitParameter("resetEnable", properties.getResetEnable());// 禁用HTML页面上的“Reset All”功能
}
return reg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 cuisongliu@qq.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cuisongliu.druid.autoconfigure;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* druid servlet properties
* @author cuisongliu
* @since 2017/5/18
*/
@ConfigurationProperties(prefix = DruidServletProperties.DRUID_SERVLET_PREFIX)
public class DruidServletProperties {
public static final String DRUID_SERVLET_PREFIX = DruidProperties.DRUID_PREFIX+".servlet";

private Boolean enable = true;
private String urlMappings = "/druid/*";
private String allow;// IP白名单 (没有配置或者为空,则允许所有访问)
private String deny; //IP黑名单 (存在共同时,deny优先于allow)
private String loginUsername;//用户名
private String loginPassword;// 密码
private String resetEnable;// 禁用HTML页面上的“Reset All”功能

public String getUrlMappings() {
return urlMappings;
}

public void setUrlMappings(String urlMappings) {
this.urlMappings = urlMappings;
}

public String getAllow() {
return allow;
}

public void setAllow(String allow) {
this.allow = allow;
}

public String getDeny() {
return deny;
}

public void setDeny(String deny) {
this.deny = deny;
}

public String getLoginUsername() {
return loginUsername;
}

public void setLoginUsername(String loginUsername) {
this.loginUsername = loginUsername;
}

public String getLoginPassword() {
return loginPassword;
}

public void setLoginPassword(String loginPassword) {
this.loginPassword = loginPassword;
}

public String getResetEnable() {
return resetEnable;
}

public void setResetEnable(String resetEnable) {
this.resetEnable = resetEnable;
}

public Boolean getEnable() {
return enable;
}

public void setEnable(Boolean enable) {
this.enable = enable;
}
}
2 changes: 1 addition & 1 deletion gradle/allproject.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
allprojects {
apply from: "$rootDir/gradle/extra/ext.gradle"
group 'com.cuisongliu'
version = "${duridVersion}"
version = "${duridVersion}.01"
repositories {
mavenLocal()
maven { url "$nexusUrl" }
Expand Down
1 change: 1 addition & 0 deletions gradle/subprojects/druid-spring-boot-autoconfigure.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ def springBootGroup = "org.springframework.boot"
dependencies {
compile "${springBootGroup}:spring-boot-autoconfigure:${springBootVersion}"
optional "${springBootGroup}:spring-boot-configuration-processor:${springBootVersion}"
optional "${springBootGroup}:spring-boot-starter-web:${springBootVersion}"
optional "com.alibaba:druid:${duridVersion}"
}

0 comments on commit 5aafd81

Please sign in to comment.