java - Create multiple beans from one method in @Configuration class -
I'm Spring for DI and I'm using No XML.
Based on configuration (for example, an XML / Property File), I am looking to create a specific type of beans (the exact number is determined by the configuration) so that in my context So that they could be autowired in the classroom. By autowire: I Then I can do something like this: ... but this "feeling" is not correct ... What is the "spring" way of achieving this? Edit: Imagine this code, where @confuturation
@Autowired Public MyClass (list
@configuration
.
@configeration public microformation class {@ etowair public videconfig (application contact reference) {// register stuff here} }
To
and Ty
are only empty class definitions.
@config configuration public group S {@ Bean public collection & lt; Ty & gt; TyList () {New Array List & lt; Ty & gt; () {{This.add (new Ty ()); // May be a number of times instances }}; } @ Bean to public (collections & lt; Ty & gt; typelists) {back to new (); }}
I'm not sure if I understood you correctly but I Believe it This is what you want.
Public Interface MyStuff {void doSomething (); } @ Scope ("Prototype") // 1 @ Service ("Goods A") 2/2 Public Segment MystuffImpallA MyStuff Execution {public void doSomething () {// your stuff}} @ scope ("prototype") @ service ("StuffB") public class applies MyStuffImpl_B MyStef {Public Zero doSomething () {// B to your stuff;)}}
You can now:
Public Class UseTheStuff {@Autowired Private Provider & lt; MyStuff & gt; StuffA; // 3 @ Incompatible Private Provider & lt; MyStuff & gt; StuffB; // 4 public zeros doStuffWithTheProvider () {MyStuff stuffA.get (); // 5 Mystuff luggage BGET (); One Provider Receive a provider (name "luggage B" tells Spring to inject a MUSTFIMprogram provider) Get a provider (name "luggage A" asks to inject a micefimple_a provider in the spring To make an example of MyStuffImpl_A to Provider MyStuffImpl_B
Comments
Post a Comment