Java – using registershutdownhook() in the spring framework

I follow this tutorial online

But when I use eclipse, I get an error when I get to this line: context registerShutdownHook();

Eclipse says:

"There are multiple marks on this line - syntax error, insert" assignmentoperator expression "to complete the assignment - syntax error, insert"; " Completion declaration – for type, the registershutdownhook() method does not define the "application context"

I'm following this tutorial All my variable names are exactly the same My code is exactly the same as him I don't know what the problem is

What I did wrong and what I can do to solve this problem so that I can continue the tutorial

Solution

For errors, it seems that the context is the object of ApplicationContext, and in the tutorial, it should be the object of abstractapplicationcontext

I just guess you wrote this

public class MainApp {
   public static void main(String[] args) {

      ApplicationContext context = 
                          new ClassPathXmlApplicationContext("Beans.xml");//error here

      HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
      obj.getMessage();
      context.registerShutdownHook();
   }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>