Announcement Announcement Module

JavaConfig forum decommissioned in favor of Core Container

As described at

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:

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at
See more
See less
log4j configuration with JavaConfig Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 [email protected]: display name [ [email protected]]; 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 [ [email protected]]: [email protected]
    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.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 or log4j.xml in your classpath.