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é!

Articles connexes


Échec de l'initialisation du contexte Spring

Isma9: Je fais un exemple de projet en suivant les étapes d'un site Web et me donne un bug bizarre et je ne peux pas le corriger, et je suis désespéré :(. HelloController.java: package com.companyname.springapp.web; import java.io.IOException; import javax.s

Initialisation du contexte Spring de la fonction Java AWS Lambda

Nitesh Kumar Je suis nouveau sur AWS Lambda. Si j'utilise le framework d'injection de dépendances Spring dans ma fonction Java Lambda, comment et quand le contexte d'application Spring est-il initialisé? UN D L'utilisation d'un cadre d'injection à ressort est

Échec de la mise en œuvre HMAC

K. Biermann J'espère que c'est le bon forum; Je n'étais pas sûr de devoir poser cette question dans stackoverflow, cryptographie ou sécurité. Donc mon problème est que la fonction hash_hmac de php n'est disponible qu'avec php> = 5.1.2. Puisque certains serveur

Échec de conversion implicite de la liste d'initialisation

bluescarni Considérez l'extrait: #include <unordered_map> void foo(const std::unordered_map<int,int> &) {} int main() { foo({}); } Cela échoue avec GCC 4.9.2 avec le message: map2.cpp:7:19: error: converting to ‘const std::unordered_map<int, int>’ f

Échec de la définition de l'ID dans la mise en page Android

Geoff Je voudrais définir un identifiant pour ma mise en page par programme, mais il affiche toujours une erreur même s'il s'exécute très bien, Comment puis-je mettre fin à l'erreur affichée dans le code: RelativeLayout newlayout = new RelativeLayout(getContex

Problème d'initialisation du contexte dans Spring Boot

utilisateur8874423 Je suis novice dans Spring Boot, j'essaie de créer une application simple à l'aide de Spring Boot, j'obtiens l'erreur suivante : org.springframework.beans.factory.UnsatisfiedDependencyException : Erreur lors de la création du bean avec le no

Échec de la mise à jour d'UITableView

Valentin Cousien Besoin de votre aide les gars ! Je deviens fou sur un bug sur iOS 9 uniquement. Comme vous pouvez le voir ci-dessous, cela se passe bien sur iOS 11 Au départ, j'ai 4 cellules avec un statut "Nouveau" pour le neuf. Lorsque je clique sur une "no

Échec de la session d'initialisation du flux de Corda

nitesh solanki Je suis confronté à un problème lors de l'exécution de tests de flux impliquant des états et des flux planifiés. Les états et les flux sont définis ici : Impossible d'initier une session de flux avec un autre nœud à partir d'un ScheduledFlow Les