运行基于java的java配置时java.lang.IllegalStateException?

时间:2014-09-28 20:53:04

标签: java spring spring-security

当我尝试运行基于Spring java annotation的配置时,我得到了异常跟踪

Sep 28, 2014 10:24:38 PM
org.springframework.context.support.AbstractApplicationContext
prepareRefresh INFO: Refreshing
org.springframework.context.annotation.AnnotationConfigApplicationContext@20ad9418:
startup date [Sun Sep 28 22:24:38 EET 2014]; root of context hierarchy
Exception in thread "main" java.lang.IllegalStateException: Cannot
load configuration class: com.learn.HelloWorldConfig  at
org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:378)
  at
org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263)
  at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
  at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:126)
  at
org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
  at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
  at com.learn.MainApp.main(MainApp.java:9) Caused by:
org.springframework.cglib.core.CodeGenerationException:
java.lang.reflect.InvocationTargetException-->null  at
org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
  at
org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
  at
org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
  at
org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:128)
  at
org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:100)
  at
org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:368)
  ... 6 more Caused by: java.lang.reflect.InvocationTargetException   at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)   at
org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
  at
org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
  ... 11 more Caused by: java.lang.SecurityException: class
"com.learn.HelloWorldConfig$$EnhancerBySpringCGLIB$$3f39adab"'s signer
information does not match signer information of other classes in the
same package  at
java.lang.ClassLoader.checkCerts(ClassLoader.java:895)  at
java.lang.ClassLoader.preDefineClass(ClassLoader.java:665)  at
java.lang.ClassLoader.defineClass(ClassLoader.java:758)   ... 17 more

HelloWorld.java

    public class HelloWorld {
    private String message;

    public void setMessage(String message){
        this.message = message;
    }
    public void getMessage(){
        System.out.println("Your Message : " + message);
    }
}

HelloWorldConfig.java

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    @Configuration
    public class HelloWorldConfig { 
        @Bean
        public HelloWorld helloWorld(){
            return new HelloWorld();
        }
    }

MainApp.java

     import org.springframework.context.annotation.AnnotationConfigApplicationContext;
        public class MainApp {
            public static void main(String[] args) {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                ctx.register(HelloWorldConfig.class);
                ctx.refresh();
                HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
                helloWorld.setMessage("Hello World!");
                helloWorld.getMessage();
                ctx.close();
                System.out.println("Test");
            }
        }

为什么我会遇到这种情况?

0 个答案:

没有答案