Я пытаюсь следовать примеру в разделе @Configuration & @Bean Annotations по ссылке https://www.tutorialspoint.com/spring/spring_java_based_configuration.htm, и у меня возникло следующее исключение:
Dec 31, 2018 2:59:33 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2dda6444: startup date [Mon Dec 31 14:59:33 EST 2018]; root of context hierarchy
Exception in thread "main" java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:298)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:230)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:153)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:139)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:282)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
at com.tutorialspoint.MainApp.main(MainApp.java:9)
Я использую java 1.8, spring 3.2.1. Спасибо за вашу помощь.
package com.tutorialspoint;
import org.springframework.context.annotation.*;
@Configuration
public class HelloWorldConfig {
@Bean
public HelloWorld helloWorld(){
return new HelloWorld();
}
}
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);
}
}
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();
}
}
Это не удалось на новом контексте AnnotationConfigApplicationContext (HelloWorldConfig.class) в MainApp.java
попробуйте, указав полный путь new AnnotationConfigApplicationContext(com.tutorialspoint.HelloWorldConfig.class);
Спасибо за ответ. При загрузке класса обнаружились проблемы с безопасностью. Пытался указать название пакета, ошибка не исчезла.




Если можете, используйте Spring 4.1.6, как указано в руководстве.
Я воспроизвел вашу ошибку с помощью spring-framework-3.2.1.RELEASE-dist.zip, но приложение Hello World у меня нормально работало с spring-framework-4.1.6.RELEASE-dist.zip.
Спасибо за предложение. Я использовал последнюю версию, и она отлично сработала.
Можете ли вы обновить код и лучше объяснить, на каком этапе вы получили это