la mise en place Spring dans Eclipse - Échec d'initialisation de contexte
krenkz:
Je suis en train de mettre en place Eclipse (être un débutant en Java et Eclipse et Spring) suivant ce tutoriel et en essayant de courir simple HelloWorld.java, je reçois cette erreur dans ma console
bře 28, 2020 6:58:18 ODP. org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorld' defined in class path resource [Beans.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.tutorialspoint.HelloWorld]: Is the constructor accessible?; nested exception is java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils (in module spring.beans) cannot access class com.tutorialspoint.HelloWorld (in module HelloSpring) because module HelloSpring does not export com.tutorialspoint to module spring.beans
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorld' defined in class path resource [Beans.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.tutorialspoint.HelloWorld]: Is the constructor accessible?; nested exception is java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils (in module spring.beans) cannot access class com.tutorialspoint.HelloWorld (in module HelloSpring) because module HelloSpring does not export com.tutorialspoint to module spring.beans
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at [email protected]/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at [email protected]/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at [email protected]/org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:882)
at [email protected]/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at [email protected]/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at [email protected]/org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at [email protected]/org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at HelloSpring/com.tutorialspoint.MainApp.main(MainApp.java:9)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.tutorialspoint.HelloWorld]: Is the constructor accessible?; nested exception is java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils (in module spring.beans) cannot access class com.tutorialspoint.HelloWorld (in module HelloSpring) because module HelloSpring does not export com.tutorialspoint to module spring.beans
at [email protected]/org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
at [email protected]/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at [email protected]/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312)
... 13 more
Caused by: java.lang.IllegalAccessException: class org.springframework.beans.BeanUtils (in module spring.beans) cannot access class com.tutorialspoint.HelloWorld (in module HelloSpring) because module HelloSpring does not export com.tutorialspoint to module spring.beans
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:647)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:490)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at [email protected]/org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204)
... 15 more
Je ne peux pas comprendre ce qui est faux?
mon code dans 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);
}
}
mon code dans MainApp.java
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
AWellPlacedCactus:
Il serait utile que vous nous fournissez le code java. Mais, sur la base des erreurs , je crois qu'il ya un fichier corrompu lorsque vous installez le programme. Assurez - vous qu'il n'y a pas de restrictions sur l'ordinateur que vous utilisez et réinstaller le programme Utilisez ce Tutoria l au lieu. Espoir qui a aidé!