java - Using spring @Transactional for the beans created using factory method? -


I am using spring 3. I have classes I

transport. Java

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

car.zava

  package com.net.core.ioc; Public-class carriage transport transport {The name of string; Public car (string name) {this.name = name; } Public Zero doSave () {// Savings Argument using name}}  

bus. Java

  package com.net.core.ioc; Public Category Bus Transportation Transport {String ID; Public bus (string id) {this.id = id; } Public Zero doSave () {// Savings Argument using ID}  

SpringService.java

  package com.net.core.ioc; Public Class Service Provider {Private Static Service Service Service = New Service Provider (); // Static Factory Law Public Stable Seva Service () {Return Service; } // Method of Instant Factory: Make Public TransportationKarastain (name of string) {Return to new car (name); } Make public transportBus instance (string ID) {return new bus (ID); }}}  

config.xml

  & lt; Reference: component-scan base-package = "com.net.core.ioc" /> & Lt; Bean id = "service locator" category = "com.net.core.ioc.ServiceLocator" factory-method = "making service" /> & Lt; Bean id = "Spring Sverker Instance" factory-bean = "service locator" factory-method = "makeover instance" scope = "prototype" /> & Lt; Bean id = "Spring Esbear's instance" factory-bean = "service locator" factory-method = "MakeObsInstance" scope = "prototype" /> & Lt; / Bean & gt;  

Now I'm getting the bean down:

  transport request = (transport) applicationContext.getBean ("springServiceCarInstance", "Something"); Request.doSave ();  

Now can I use spring trading here? I mean I use cars and bus classes @ Transactional?

can not, as the car and bus has not been constructed by the spring factory , The examples you get will not be behind the transaction screen, so annotations will be useless.

If you want to start it through Spring Contract, Bean or Make Bean For more information, see JAVA doctor.

Alternatively, you can register Can and Bus as prototype beans, with spring reference, and use only getBean ("Beename", Beantype.Class) and spring will always return You are their new examples.

@Component @Scope ("Singleton") Public Category Carfactor {@Autowired Private AutowireCapableBeanFactory autowireCapableBeanFactory; Public car making (make, model model, year of year) {car car = new car (make, model, year); // It will be applicable to post processors that wrap the transaction bin like intermediate beacons etc. Car Carropy = Car. Class.cast (autovair capbelfater.config configure bane (car, "carben")); Return Carrropoxy; }}

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 -