-
Aug 24th, 2012, 03:34 PM
#1
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
-
Aug 24th, 2012, 03:56 PM
#2
I discovered the problem, I had to load the asm-3.3.1.jar also, working fine now.
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules