@Configuration public class DataSourceConfig { @Bean public ServletRegistrationBean statViewServlet(){ ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*"); Map<String, String> initMap = new HashMap<>(); initMap.put(StatViewServlet.PARAM_NAME_JMX_USERNAME,"admin"); initMap.put(StatViewServlet.PARAM_NAME_JMX_PASSWORD,"123456"); initMap.put("loginUsername", "admin"); initMap.put("loginPassword", "123456"); bean.setInitParameters(initMap); return bean; } @Bean public FilterRegistrationBean webStatFilter(){ FilterRegistrationBean bean = new FilterRegistrationBean(); bean.setFilter(new WebStatFilter()); Map<String, String> initMap = new HashMap<>(); bean.setInitParameters(initMap); bean.setUrlPatterns(Arrays.asList("/*")); return bean; } }