using registerShutdownHook() in the Spring Framework

后端 未结 6 2370
深忆病人
深忆病人 2021-02-08 22:14

I am following this tutorial online to the letter. http://www.tutorialspoint.com/spring/spring_bean_life_cycle.htm

But I get the errors when using Eclipse when I get to

6条回答
  •  無奈伤痛
    2021-02-08 22:40

    Here is the code that worked for me.

    package arjun;
    
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.AbstractApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.core.io.FileSystemResource;
    
    public class Main {
    
        public static void main(String[] args) {
    
                    AbstractApplicationContext context= new ClassPathXmlApplicationContext("spring.xml");
                    context.registerShutdownHook();
                    Triangle triangle=(Triangle) context.getBean("triangle");
                    triangle.draw();
        }
    
    }
    

提交回复
热议问题