2010-07-19 4 views
3

Je travaille sur un projet utilisant Spring, Hibernate et Struts2. Les requêtes et les sorties système sont enregistrées deux fois. J'ai jar slf4j-api-1.6.1 et slf4j-log4j12-1.6.1 dans le dossier lib.hibernate double logging

log4j.properties

log4j.logger.org.hibernate=info 

applicationContext.html

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

<!-- The singleton hibernate session factory --> 
<bean id="sessionFactory" scope="singleton" 
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="configLocation" value="classpath:hibernate.cfg.xml" /> 
</bean> 

<!-- Spring's hibernate transaction manager, in charge of making hibernate sessions/txns --> 
<bean id="transactionManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

<!-- So classes/functions with @Transactional get a hibernate txn --> 
<tx:annotation-driven /> 
<!-- Inject my business services class to the actions --> 
<bean id="services" class="dao.Services" scope="singleton"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

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> 
<!-- Database connection settings --> 
<session-factory name=""> 
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
    <property name="hibernate.connection.url">jdbc:mysql://localhost/ciner</property> 
    <property name="hibernate.connection.username">root</property> 
    <property name="connection.password" /> 
    <property name="connection.pool_size">1</property> 
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
    <property name="hbm2ddl.auto">update</property> 
    <!-- 
    Exception was thrown. Thus removed, until fix is found. Enable c3p0 
    connection pooling, because hibernate pooling is not prod-ready. 
    Apparently connection.provider_class is needed in hibernate 3+ 
    <property 
    name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 
    <property name="c3p0.max_size">100</property> <property 
    name="c3p0.min_size">1</property> <property 
    name="c3p0.idle_test_period">30</property> Echo all executed SQL to 
    stdout for debugging 
    --> 
    <property name="show_sql">true</property> 
    <property name="format_sql">true</property> 
    <!-- 
    All the entity classes for hibernate to check for annotations here 
    --> 

</session-factory> 
</hibernate-configuration> 

struts.xml

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
"http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<!-- set to false for prod --> 
<constant name="struts.devMode" value="true" /> 

<package name="default" extends="struts-default"> 


</package> 

</struts> 

Sortie

20:57:23,338 INFO [STDOUT] Hibernate: 
select 
     newhire0_.employee_id as employee1_10_, 
     newhire0_.active_status as active2_10_, 
     newhire0_.cost_center as cost3_10_, 
     newhire0_.credit_training as credit4_10_, 
     newhire0_.development_plan as developm5_10_, 
     newhire0_.development_session as developm6_10_, 
     newhire0_.development_training as developm7_10_, 
     newhire0_.employee_market as employee8_10_, 
     newhire0_.end_date as end9_10_, 
     newhire0_.first_offer_letter_sent as first10_10_, 
     newhire0_.hire_date as hire11_10_, 
     newhire0_.housing_required as housing12_10_, 
     newhire0_.last_review_date as last13_10_, 
     newhire0_.last_review_type as last14_10_, 
     newhire0_.last_reviewer_name as last15_10_, 
     newhire0_.new_hire_first_name as new16_10_, 
     newhire0_.new_hire_last_name as new17_10_, 
     newhire0_.lob_id as lob18_10_, 
    from 
     ciner.new_hire newhire0_ 
    order by 
     newhire0_.hire_date, 
     newhire0_.lob_id, 
     newhire0_.new_hire_last_name, 
     newhire0_.new_hire_first_name 
20:57:24,458 INFO [STDOUT] Hibernate: 
select 
     newhire0_.employee_id as employee1_10_, 
     newhire0_.active_status as active2_10_, 
     newhire0_.cost_center as cost3_10_, 
     newhire0_.credit_training as credit4_10_, 
     newhire0_.development_plan as developm5_10_, 
     newhire0_.development_session as developm6_10_, 
     newhire0_.development_training as developm7_10_, 
     newhire0_.employee_market as employee8_10_, 
     newhire0_.end_date as end9_10_, 
     newhire0_.first_offer_letter_sent as first10_10_, 
     newhire0_.hire_date as hire11_10_, 
     newhire0_.housing_required as housing12_10_, 
     newhire0_.last_review_date as last13_10_, 
     newhire0_.last_review_type as last14_10_, 
     newhire0_.last_reviewer_name as last15_10_, 
     newhire0_.new_hire_first_name as new16_10_, 
     newhire0_.new_hire_last_name as new17_10_, 
     newhire0_.lob_id as lob18_10_, 
    from 
     ciner.new_hire newhire0_ 
    order by 
     newhire0_.hire_date, 
     newhire0_.lob_id, 
     newhire0_.new_hire_last_name, 
     newhire0_.new_hire_first_name 
20:57:24,962 INFO [STDOUT] FA/2010, Chief Information Officer, John Doe1 
20:57:24,962 INFO [STDOUT] SP/2010, Unknown, John Doe2 
20:57:24,962 INFO [STDOUT] SP/2010, Chief Information Officer, John Doe3 
20:57:24,990 INFO [STDOUT] FA/2010, Chief Information Officer, John Doe1 
20:57:24,990 INFO [STDOUT] SP/2010, Unknown, John Doe2 
20:57:24,991 INFO [STDOUT] SP/2010, Chief Information Officer, John Doe3 
+0

Pouvez-vous montrer une sortie représentative pour avoir une idée? De même, comment la journalisation est-elle configurée pour Spring? Utilisez-vous toujours Commons Logging for Spring? –

+0

Avez-vous configuré votre appender log4j pour qu'il ne soit pas additif? –

+0

voir commentaire ci-dessous – Nish

Répondre

0

il est difficile de dire sans voir le code, mais je suppose que vous êtes votre enregistreur deux fois en train de configurer. Etes-vous sûr que vous n'avez pas

BasicConfigurator.configure() 

partout dans votre code?

+0

@Pascal - J'ai ajouté ma sortie ci-dessus. Je ne pense pas avoir configuré la journalisation pour Spring. J'ai jons communs dans mon dossier lib si. @binil - Comment configurer l'appender log4j pour qu'il ne soit pas additif? @hvgotcodes - Non, je ne sais pas. Y a-t-il une autre configuration que vous souhaitez que je poste? – Nish

0

Nishant, essayez:

log4j.additivity.org.hibernate=false 
+0

juste essayé, pas de chance! :( – Nish