java - Using spring to instantiate with static factory methods? -


I am using spring 3. I have classes

Transport.java

  package com.net.core.ioc; Public Interface Transport {Public Zero GetTransport (); }  

car.zava

  package com.net.core.ioc; Public category car transport {Public is zero getTransport () {System.out.println ("transport type car is"); }}  

Bus.Java

  package com.net.core.ioc; Public Category Bus Transportation Transport {Public Zero GetTransport () {System.out.println ("Transport Type is Car"); }  

SpringService.java

  package com.net.core.ioc; Public Spring Springs Service {Private Stable Spring Service Service = New SpringsWire (;); // static factory method public stable SpringService createService () {return service; } // Instant Factory's way of making public transport () (new car back); } Making public transportationBus Instance () {new bus (return); }}}  

config.xml

  & lt; Reference: component-scan base-package = "javabeat.net.core.ioc" /> & Lt; Bean id = "springServiceStaticFactory" factory-method = "making service" /> & Lt; Bean id = "Spring Svervar Instance" factory-bean = "Spring Service Service Factory" factory-method = "MakeOver Instance" / & gt; & Lt; Bean id = "Spring Eserbus Instance" factory-bean = "Spring Service Service Factory" factory-method = "Beobus instance" /> & Lt; / Bean & gt;  

Now my question spring spring and bus instances using the Spring Swarj.Java class? Because I have to annotate cars and bus classes with @transnational annotations. Is this possible?

"post-text" itemprop = "text">

The spring will manage your car and bus as an example, they ApplicationContext are part of . What you are doing is basically the same as with the spring factory bean but now you are using your own system

However, your current In Setup, cars and bus are single songs because they will be created once, not sure what you want.

If you want to pass the constructor to the value, then just modify your factory method.

  Creating public transportationKarinestens (name of string) {Return new car (name); }  

The definition of your bean should be told that it is a prototype skid bean

  & lt; Bean id = "springServiceCarInstance" factory-bean = "springstestatic factory" factory -method = "createCarInstance" scope = "prototype" />  

Now in your code you see the lookup method (see) Look in and make arguments nearby.

@ ATVOIER Private AppContacts CTX; Public Zero My Mathew () {Car Car = CTX .get Bean (Car Class, "Mercedes"); }

The above code should give you a new car with the name Mercedes .


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -