java - Spring bean configuration to use singleton or prototype? -
I am using Java 7 and Spring 3. I'm below the classes.
Request. Java
Public Interface Request {Public Zero doProcess (); }
RequestImpl.java
@Transportable Public Category RequestImpl applies {request} private string name; Private string era; // Setsers and Gates Public Wide Do Process () {// Usage name and call age and third party class which will secure database in database}}
SpringConfig.xml
& lt; Bean id = "request" category = "pkg.RequestImpl.java" />
The client will now use RequestImpl as the following.
RequestImplreq = (RequestImpl) applicationContext.getBean ("request"); Req.setName ("SomeName"); Req.setAge ("20"); Req.doProcess ();
Now my question is do I have to declare the RequestImpl.java scope as a prototype or singleton?
Thank you!
IMHO you are not working well: data must be separated from process and process ( ) Then doProcess ()
should be defined doProcess (name, age)
or shaded behind a factory or something similar.
Perhaps the best option is to define
public interface request {public zero doProcess (string name, string era); } @ Transaction Public Class Request Enforced Implementation {The process of working with the public zero (string name, string era) {// what you want to do}}
your SpringConfig Keep the same XML and change to the call code:
request REQ = applicationContext.getBean (Request.class); Req.doProcess ("Some Name", "20");
Except for everyone, perform a applicationContext.getBean ()
and the result of an implementation (usually) bad retraction because the spring proxy can return the object And can be cast for implementation, will fail from a ClassCastException
Comments
Post a Comment