log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.自学hibernate,看的是尚学堂,马士兵的hibernate3.3.2的视频,在构建log4j这个日志时候由于出现了问题后,我重头一步一步的按照马老师的步骤进行,下了和老师一样的架包,不过我用的是eclipse 3.5的,mysql 6.0 。1.
hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory> <!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">364200</property> <!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property> <!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property> <!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="format_sql">true</property> <!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property> <mapping class="com.geolo.hibernate.model.Teacher"/>
</session-factory>
</hibernate-configuration>
2.
teacher.javapackage com.geolo.hibernate.model;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;@Entity
public class Teacher {
private int id;
private String name;
private String title;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}@Column
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
3.
teachertest.javaimport org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;import com.geolo.hibernate.model.Student;
import com.geolo.hibernate.model.Teacher;
public class TeacherTest {
public static void main(String[] args){
Teacher t = new Teacher();
t.setId(111);
t.setName("huhu");
t.setTitle("p");
Configuration cfg = new AnnotationConfiguration();
SessionFactory sf = cfg.configure().buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
session.close();
sf.close();
}
}
log4j:WARN Please initialize the log4j system properly.自学hibernate,看的是尚学堂,马士兵的hibernate3.3.2的视频,在构建log4j这个日志时候由于出现了问题后,我重头一步一步的按照马老师的步骤进行,下了和老师一样的架包,不过我用的是eclipse 3.5的,mysql 6.0 。1.
hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory> <!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">364200</property> <!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property> <!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property> <!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="format_sql">true</property> <!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property> <mapping class="com.geolo.hibernate.model.Teacher"/>
</session-factory>
</hibernate-configuration>
2.
teacher.javapackage com.geolo.hibernate.model;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;@Entity
public class Teacher {
private int id;
private String name;
private String title;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}@Column
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
3.
teachertest.javaimport org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;import com.geolo.hibernate.model.Student;
import com.geolo.hibernate.model.Teacher;
public class TeacherTest {
public static void main(String[] args){
Teacher t = new Teacher();
t.setId(111);
t.setName("huhu");
t.setTitle("p");
Configuration cfg = new AnnotationConfiguration();
SessionFactory sf = cfg.configure().buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
session.close();
sf.close();
}
}
邮箱:[email protected]
让我来给终结一下吧
log4j:WARN No appenders could be found for logger (XXXXX).
log4j:WARN Please initialize the log4j system properly.
一般情况下,说明你的log4j.properties内容或位置配置不当,但不会影响你的其他操作。
so,有2种方法参考一下:
第一,修改你的log4j.properties文件,大概如下:# Configure logging for testing: optionally with log file
log4j.rootLogger=WARN, stdout
# log4j.rootLogger=WARN, stdout, logfilelog4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%nlog4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=target/spring.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n第二,挪挪log4j.properties的地方,1是按照官方的英文说明应该首选放在src下的或者部署的路径下,2是放在指定路径下如WEB-INF/config/log4j.properties,这时,你就需要在web.xml里指定路径了,参考配置代码:
<!-- Log4J的配置信息 -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>logs.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
在此,强烈建议放在src下,换路径配置时不能保证没有警告信息。
log4j.rootLogger=debug,logger注意这个地方(logger)
log4j.appender.logger=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logger.File=E:/logs/DataTransfer.log
#log4j.appender.logger.File=${catalina.home}/logs/SupportWS.log
#log4j.appender.logger.MaxFileSize=10MB
#log4j.appender.logger.MaxBackupIndex=1000
log4j.appender.logger.layout=org.apache.log4j.PatternLayout
log4j.appender.logger.layout.ConversionPattern=[DataTransfer][%d{yyyy-MM-dd HH\:mm\:ss}][%l]\:%m%n
log4j.rootLogger=warn, stdout