Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
log4j configuration with JavaConfig Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • log4j configuration with JavaConfig

    I have a standalone (not web) application using JavaConfig and when I start the app I get the following log entries:

    2009/01/16 20:59:36:529 GMT [INFO] JavaConfigApplicationContext - Refreshing org.springframework.config.java.context.JavaConfig ApplicationContext@4c2d0479: display name [org.springframework.config.java.context.JavaConfig ApplicationContext@4c2d0479]; startup
    date [Fri Jan 16 20:59:36 GMT 2009]; root of context hierarchy
    2009/01/16 20:59:36:667 GMT [INFO] JavaConfigApplicationContext - Bean factory for application context [org.springframework.config.java.context.JavaConfig ApplicationContext@4c2d0479]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@4d16318b
    2009/01/16 20:59:37:054 GMT [INFO] ConfigurationModelBeanDefinitionReader - Registering PUBLIC bean definition for @Configuration ... etc.

    I have tried to control the logging with the following @Configuration class:

    @Configuration(defaultLazy = Lazy.FALSE)
    public class Log4jConfig {
    @Bean(lazy = Lazy.FALSE)
    public MethodInvokingFactoryBean log4jInitialization() {
    final MethodInvokingFactoryBean bean =
    new MethodInvokingFactoryBean();
    bean.setTargetClass(Log4jConfigurer.class);
    bean.setTargetMethod("initLogging");
    bean.setArguments(new Object[] {"spring-log4j.xml"});

    return bean;
    }
    }

    ... but it doesn't seem to work - the app still spews the same log entries as before. The @Bean corresponds to the bean definition XML that supposedly controls log4j settings in a Spring XML configuration.

    Any ideas?

    Thanks in advance.

  • #2
    Looks like a chicken-and-egg problem. The output that you're seeing is log4j output that happens before that @Bean gets processed. You can suppress or otherwise influence this by configuring the usual log4j.properties or log4j.xml in your classpath.

    Comment

    Working...
    X