DRUID连接池的实用 配置详解

所需积分/C币:50 2016-10-20 14:52:23 102KB PDF

DRUID连接池的实用 配置详解
<bean id="log Filter"class="com. a libaba druid filter. logging. slf4j Log Filter property name="statement Executa bleSqllogEnable"value=false"/> bean> </beans> 上面红色标注部分为监控DB连接执行监控,后面在做详细说明 ·监控方式 1、WEB方式监控配置 <servlet> <servlet-narne >Druidstat View </servlet-name> <servlet-class>com.alibabadruidsupporthttpstatviewservlet</servlet-class> </servlet> <servlet-mapping> <servlet -name >Druid Stat View </servlet-name> <url-pattern>/druid/*<url-pattem> </servlet-mapping> <filter> <filter-name >druidwebstat Filter </filter-name> <filter-class>com.alibabadruidsupporthttpWebstatfilter</filter-class> <init-param> <param-name >exclusions </param-name> <param-value>/public/** js, * css druid* . jsp swf </param-value> </init-param> <init-param> <param-name>principalSession Name </param-name> <param-value >sessionInfa</param-value> <init -param> <init -param> <param-name>profile Enable </param-name> <param-value>true</paramvalue> </filter> <filter-mapping> <filter-name>druidWebstat Filter </filter-name> url-pattern>/*</url-pattern> </filter-mapping> 把上面sere配置添加到项目web.xm即可。然后运行Tomcat,洳览器输入http://ip:Prot/DruiD 就可以打开Drud的监控页面了 2、日志文件监控 Druid提供了多种口志文件监控 commons- logging、lag4j等,这里我们主要使用sf4j和 Hogback来进行日志监控配置。 首先要引入sf4j和logback相关的jar文件(从Maven公共仓库下载http://search.mavenorg/) <slf4j version>1. 7.</slf4jversion> <logback. version>l1.2</logback. version> <dependency> <groupId >org. slf 4j</groupId> <artifactId>slf4j-apicyartifactId> <version>$slf4j version</version> <dependency> <groupId>ch qos logback</groupId> <artifactld>logback-access<lartifactId> <version>$logback. version</version> </dependency> <dependency> <groupId >ch. gos logback</groupId> <artifactld>logback-core sartifactId> <version>log back. version]</version> <dependency> <groupId>ch qos logback</groupId> sartifactId>logback-classic sartifactId> <version>logback. version]</version> </dependency> 接下配置 logback的配置文件(/conf/ hogback.Xm) <configuration> appender name=STDOUT"class="ch gos logback. core. Console Appender> <layout class="ch qas logback. classic. PatternLayout> <Pattern>%od HH: mm: ssSSS [%thread]%0-5level %logger [367-%msgn </Patterm> </layout> <appender> <appender name="File"class="ch gos logback. core. FileAppender> file>/ logs/druid_ info. log</file> <layout class="ch qos logback. classic. PatternLayout> <Pattern>od HH: mm: ssSSS[%thread]%-5level %logger 36-%msg%n</Pattern> </layout> <filter class="ch gos, logback. classic filter. ThresholdFilter"> evel>debug </level> Appender> <root level="debug"> <appender-ref ref="FILE"/> </root> </configuration> 最后就是写一个测试类进行测试 public class TestMain public static void loadLoggerContexto t LoggerContext Ic=( LoggerContext) LoggerFactory getILoggerFactory();25 System get Properties( put( logback. configurationFile ,"./conf/ logback. xml") Stat us Printer. setPrint Stream( System. err Stat us Printer print(Ic) public static void main(String] argsi loadLoggerContexto FileSystemXmlApplication Context context new File SystemXmlApplicationContext( /conf/ spring-base. xml); s catch(Exception et System. out. printin(e); 标签: DRUID连接池配置详解

...展开详情

评论 下载该资源后可以进行评论 1

zqxvip 挺好的,选择用spring-boot-druid-starter更方便
2017-12-28
回复
img
gdxsuper

关注 私信 TA的资源

上传资源赚积分,得勋章
最新资源