Im creating a application in java SE witht spring framework. I have defined some frames in my application context:
ApplicationContext actx = new FileSystemXmlApplicationContext(args[0]);
context.xml:
<bean id="NewRouteFrame" class="newRoute.frame.NewRouteFrame"
lazy-init="true"
/>
<bean id="NewControllerFrame" class="newController.frame.NewControllerFrame"
lazy-init="true"
/>
and sometimes i would like to create a new object-frame (destroy old frame and create new one).
Im using dispose method after window will closed (i dont want cache frames):
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
but spring still caching a frame. When i create normal frame using keyword
new MyJFrame();
disposing works correct. But throught spring context not!. I can set scope="prototype" in context.xml than spring will create new Frame, but old frame still existsing resulting many same frames. How it is possible to destroy object?. I would like to destroy object from spring context using listener close window operation for example:
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
// here destroy bean from context, but how???
}
});
}
I will great full for help in this issue
UPDATE
i not use @Authowire annotation. I get simple beans using:
appContext.getBean(MyFrame.class);
My problem is that i don`t know how to delete already existing object (frame) in appContext and after this again call new MyJFrame (fresh) object. How i wrote above i can use scope="prototype" but after this i get alot of same frames. So this is not satisfity me