java - Common value configuration in Spring XML -


I have several spring beans in which the property value is the same for all of string . Is there any way where I can define string in XML at one place and can reference it in all the beans on the value settings of the property?

  & lt; Bean id = "some bean" class = "test.SomeBean" & gt; & Lt; Property Name = "Property 1" Ref = "Some Value" & gt; & Lt; / Property & gt; & Lt; Property Name = "General Property" Value = "General Value" & gt; & Lt; / Property & gt;   

  & lt; Bean id = "next bean" class = "test.extBean" & gt; & Lt; Property name = "property 2" ref = "some value" & gt; & Lt; / Property & gt; & Lt; Property Name = "General Property" Value = "General Value" & gt; & Lt; / Property & gt;   

How to set commonValue in a different place and see it in both places?

Try this way.

  & lt; Bean id = "commonConfig" abstract = "true" & gt; & Lt; Property Name = "Amphil" Value = "General Value" & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt; Bean id = "class 1" class = "com.dataclass.Class1" parent = "commonConfig" & gt; & Lt; Property Name = "Field 1" Value = "Value 1" & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt; Bean id = "square 2" class = "com.dataclass.Class2" parent = "commonConfig" & gt; & Lt; Property Name = "Field2" Value = "Value 2" & gt; & Lt; / Property & gt; & Lt; / Bean & gt;   

class 1 & amp; A common field name for Class 2 is "AmphilD", the original attribute is used only for this common purpose.

In the spring it is called Bean Definition Heritage (This is not Java class succession, for example above class 1 and N class is not inherited in its respective java file.)

For more information, check Spring Dock.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -