基于Spring 3.1 Java的配置-IllegalStateException [英] Spring 3.1 Java based configuration -- IllegalStateException

查看:87
本文介绍了基于Spring 3.1 Java的配置-IllegalStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照Spring教程的方式工作,我使用基于Java的配置的以下代码无法正常工作。在我的类路径中,我有Spring 3.1 jar,asm-4.0.jar和cglib-2.2.2.jar。

I am working my way through a Spring tutorial, I have the following code, using Java based configuration, that isn't working. In my classpath I have the Spring 3.1 jars, as well as asm-4.0.jar and cglib-2.2.2.jar.

MainApp.java:

MainApp.java:

package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

public class MainApp {
    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(
                HelloWorldConfig.class);
        HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
        helloWorld.setMessage("Hello World!");
        helloWorld.getMessage();
    }
}

HelloWorldConfig.java:

HelloWorldConfig.java:

package com.tutorialspoint;

import org.springframework.context.annotation.*;

@Configuration
public class HelloWorldConfig {
    @Bean
    public HelloWorld helloWorld() {
        return new HelloWorld();
    }
}

HelloWorld.java:

HelloWorld.java:

package com.tutorialspoint;

public class HelloWorld {
    private String message;

    public void setMessage(String message) {
        this.message = message;
    }

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

错误代码:

Exception in thread "main" java.lang.IllegalStateException: Cannot load configuration class: com.tutorialspoint.HelloWorldConfig
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:456)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigurationClasses(ConfigurationClassPostProcessor.java:202)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:176)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:604)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:437)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:68)
    at com.tutorialspoint.MainApp.main(MainApp.java:8)
Caused by: java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method visit.(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at net.sf.cglib.core.AbstractClassGenerator.<init>(AbstractClassGenerator.java:38)
    at net.sf.cglib.core.KeyFactory$Generator.<init>(KeyFactory.java:127)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:112)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:101)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:89)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:448)
    ... 6 more


推荐答案

我从asm-4.0更改了asm jar文件。 jar到asm-3.3.jar,它起作用了。第一个asm jar和我使用的cglib jar之间肯定存在冲突。

I changed the asm jar file from asm-4.0.jar to asm-3.3.jar, and it worked. There must have been a conflict between the first asm jar and the cglib jar I was using.

这篇关于基于Spring 3.1 Java的配置-IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆