一个简单的运用Spring实现的例子
配置文件applicationcontext.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?> flxMainClass.java文件:
package cn.itcast;
import java.util.*;
import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.BeanFactory;
public class MainClass
{
public static void main(String [] args) throws Exception
{
PropertyConfigurator.configure(“logFourj/log4jdome.properties”);
Logger loger = Logger.getLogger(Manclass.class);
Collection objCollection = CollectionFactory.getCollection();
for(Object obj : objCollection)
{
loger.info(“obj.toString()”);
}
}
}
student.java文件如下:
package cn.itcast;
public class Student
{
private String name = null;
public void setMyName(String name)
{
this.name = name;
}
public String getMyName()
{
return name;
}
public String toString()
{
return name;
}
}
log4jdome.properties 文件配置如下:
#log4j.rootLogger=error, A1
#log4j.appender.A1=org.apache.log4j.ConsoleAppender
#log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
作者:yaochao
来源:CSDN
原文:https://blog.csdn.net/YaoChao/article/details/1199952
版权声明:本文为博主原创文章,转载请附上博文链接!