org.cattleframework.db.datasource.druid.DruidStatViewServletConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cattle-db-datasource Show documentation
Show all versions of cattle-db-datasource Show documentation
Cattle framework db data source component pom
The newest version!
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cattleframework.db.datasource.druid;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import com.alibaba.druid.support.jakarta.ResourceServlet;
import com.alibaba.druid.support.jakarta.StatViewServlet;
/**
* Druid统计视图Servlet配置
*
* @author orange
*
*/
@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "cattle.db.druid.stat-view-servlet", name = "enabled", havingValue = "true")
public class DruidStatViewServletConfiguration {
private static final String DEFAULT_ALLOW_IP = "127.0.0.1";
@Bean
public ServletRegistrationBean statViewServletRegistrationBean(DruidStatProperties properties) {
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean();
registrationBean.setServlet(new StatViewServlet());
registrationBean.addUrlMappings(config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*");
if (config.getAllow() != null) {
registrationBean.addInitParameter(ResourceServlet.PARAM_NAME_ALLOW, config.getAllow());
} else {
registrationBean.addInitParameter(ResourceServlet.PARAM_NAME_ALLOW, DEFAULT_ALLOW_IP);
}
if (config.getDeny() != null) {
registrationBean.addInitParameter(ResourceServlet.PARAM_NAME_DENY, config.getDeny());
}
if (config.getLoginUsername() != null) {
registrationBean.addInitParameter(ResourceServlet.PARAM_NAME_USERNAME, config.getLoginUsername());
}
if (config.getLoginPassword() != null) {
registrationBean.addInitParameter(ResourceServlet.PARAM_NAME_PASSWORD, config.getLoginPassword());
}
if (config.getResetEnable() != null) {
registrationBean.addInitParameter(StatViewServlet.PARAM_NAME_RESET_ENABLE, config.getResetEnable());
}
return registrationBean;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy