配置yml文件
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
一,添加注解
@Configuration
二 连接
@ConfigurationProperties(prefix = "spring.datasource")//连接
三,后台监控、
@Bean
public ServletRegistrationBean StatViewServlet(){
ServletRegistrationBean bean = new ServletRegistrationBean<>(new StatViewServlet(), "/diuid/**");
//后台需要有人登录 ,账号密码管理
HashMap<String, String> objectObjectHashMap = new HashMap<>();
//添加配置
objectObjectHashMap.put("loginUsername","admin"); //登录的key 都是固定的
objectObjectHashMap.put("loginPassword","123456"); //登录的key 都是固定的
//允许谁可以访问
objectObjectHashMap.put("allow","");//后面空着就是谁也可以访问
bean.setInitParameters(objectObjectHashMap);
return bean;
}
四,过滤器
@Bean
public FilterRegistrationBean webStatFilte(){
FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new WebdavFixFilter());
HashMap<String, String> objectObjectHashMap = new HashMap<>();
//这些东西不进行统计
objectObjectHashMap.put("exclusions","*.js,*.css,/druid/*");
bean.setInitParameters(objectObjectHashMap);
return bean;
}