Announcement Announcement Module
Collapse
No announcement yet.
Configuration Using Java class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuration Using Java class

    I'm trying a simple example of configuration by class injection:

    My main is

    package com.apress.prospring3.ch5.javaconfig;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.annotation.AnnotationC onfigApplicationContext;


    public class JavaConfigSimpleExample2 {

    public static void main(String[] args) {

    ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class );

    MessageRenderer renderer = ctx.getBean("messageRenderer", MessageRenderer.class);

    renderer.render();

    }

    }


    My AppConfig class is:

    package com.apress.prospring3.ch5.javaconfig;

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configurati on;

    // Inform Spring this is a java-based configuration file
    @Configuration
    public class AppConfig {

    @Bean
    public MessageRenderer messageRenderer() {
    MessageRenderer renderer = new StandardOutMessageRenderer();

    // Setter injection of MessageProvider
    renderer.setMessageProvider(messageProvider());

    return renderer;
    }

    @Bean
    public MessageProvider messageProvider() {
    return new ConfigurableMessageProvider();
    }

    }

    When I run the main I get the error:

    Exception in thread "main" java.lang.IllegalStateException: Cannot load configuration class: com.apress.prospring3.ch5.javaconfig.AppConfig

    Can anyone help? Thanks

    p.s. I do have cglib.jar in my build path

  • #2
    I discovered the problem, I had to load the asm-3.3.1.jar also, working fine now.

    Mike

    Comment

    Working...
    X