-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.0.31.01 append druid servlet auto config
- Loading branch information
1 parent
279fb29
commit 5aafd81
Showing
7 changed files
with
181 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...igure/src/main/java/com/cuisongliu/druid/autoconfigure/DruidServletAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...utoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/DruidServletProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters