Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy destroy-method is giving error in Spring MVC?
    primarykey
    data
    text
    <p>I have destroy method in my bean but it is not showing in the out put. Could you please help me here.</p> <pre><code>package com.vaannila; import org.springframework.context.ApplicationContext; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class HelloWorldApp { public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); Ticket helloWorld = (Ticket) context.getBean("ticket"); helloWorld.setTicketNo("ABC009"); helloWorld.display(); context.close(); } } </code></pre> <p>below is my xml file</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt; &lt;bean id="helloWorld" class="com.vaannila.HelloWorld"&gt; &lt;property name="message" value="Hello World!"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="ticket" class="com.vaannila.Ticket" scope="prototype" init-method="init" destroy-method="destroy"/&gt; &lt;/beans&gt; </code></pre> <p>and Ticket class is below</p> <pre><code>package com.vaannila; public class Ticket { private String ticketNo=""; public String getTicketNo() { return ticketNo; } public void setTicketNo(String ticketNo) { this.ticketNo = ticketNo; } public void display() { System.out.println("Your Ticket No. is"+ ticketNo); } public void init() { System.out.println("Bean is ready You can use it now"); } public void destroy() { System.out.println("Bean is going to destroy"); } } </code></pre> <p>The out put is giving for init method but not for destroy method.. If i changed the init-method and destroy-method as default as below it is giving error in destroying the bean called "helloWorld"</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-init-method="init" default-destroy-method="destroy"&gt; &lt;bean id="helloWorld" class="com.vaannila.HelloWorld"&gt; &lt;property name="message" value="Hello World!"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="ticket" class="com.vaannila.Ticket" scope="prototype"/&gt; &lt;/beans&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload