propertyConfigure的使用

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:dpc.properties</value>
            </list>
        </property>
    </bean>

    <bean id="guestManager" class="com.taobao.dpservice.test.sample.java.manager.impl.GuestManagerImpl" >
        <property name="dao">
            <ref bean="dao" />
        </property>
    </bean>
    <bean id="dao"  class="com.taobao.dpservice.test.sample.java.dao.impl.GuestDaoJdbc" >
        <property name="jdbcTemplate">
            <ref bean="jdbcTemplate"/>
        </property>
    </bean>

    <!-- 自动打印日志配置开始 -->
    <bean id="logInterceptor" class="com.taobao.itest.spring.aop.LogInterceptor">
        <property name="logInvokeParams" value="true" />
        <property name="logInvokeResult" value="true" />
    </bean>
    <bean
        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
            <value>guestManager</value>
        </property>
        <property name="interceptorNames">
            <list>
                <value>logInterceptor</value>
            </list>
        </property>
    </bean>
    <!-- 自动打印日志配置结束-->

</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Log4j的包下载完成后,解压,将其中打包好的的log4j-1.x.x.jar导入你的工程LIB中。 Log4j之所以受欢迎的原因之一是它的灵活性。Log4j提供了灵活的配置方法,默认是调用BasicConfigurator.configure()来进行配置,但如果只是简单的调用BasicConfigurator.configure()来进行配置工作,那么所有的配置都是固定的,不方便以后修改配置。另一种是动态配置,Log4j提供了PropertyConfigurator.configure(……)来动态配置,参数可以是一个properties文件所在路径的String对象,可以是一个properties文件所在路径的URL对象,也可以是一个properties对象。如果要用XML文件来配置信息,则可用类型的DOMConfigurator()函数来从一个XML文件中加载配置信息。这种方式更方便修改配置。 动态配置 package http; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.xml.DOMConfigurator; public class Log4jDemo { static Logger log = Logger.getLogger(Log4jDemo.class.getClass()); /** * main * @param args */ public static void main(String[] args) { BasicConfigurator.configure();//默认配置 PropertyConfigurator.configure("c:/log4j.properties"); //动态配置,参数可以是一个properties文件所在路径的String对象 //可以是一个properties文件所在路径的URL对象,也可以是一个properties对象 DOMConfigurator.configure("c:/log4j.xml");//XML配置文件 //PropertyConfigurator.configure()的参数还可以是XML、Properties对象 //下面就可使用log4j log.info("info"); log.debug("debug"); log.error("error"); log.warn("warn"); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值