Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Replace @Resource Annotation with Java 1.4 Compliant Version

I have a test class that has a @Resource annotation for a setter and I need to make it Java 1.4 compliant, so obviously the annotation has to go. I'm using Spring.

So, how would I replace something like @Resource("my.resource") so that the setter gets the correct dependency injection? Would I need to make a bean in an xml file?

I'm pretty new to this so if I'm not providing enough information, let me know.

like image 919
AHungerArtist Avatar asked Aug 31 '26 20:08

AHungerArtist


2 Answers

If you are in a Java 1.4 environment you cannot rely on Annotations as you already mentioned correctly. So you have to declare dependencies and bean definitions inside your XML-document that configures your Spring ApplicationContext.

<bean id="myBeanName" class="my.package.MyClass">
   <!-- injects otherBean into propertyName -->
   <property name="propertyName" ref="otherBean" />

   <!-- injects propertyValue into otherProperty -->
   <property name="otherProperty" value="propertyValue" />

   <!-- injects an instance of an anonymous bean into innerBean -->
   <property name="innerBean">
       <bean class="my.package.InnerBean" />
   </property>
</bean>

<bean id="otherBean" class="my.package.OtherBean" />
like image 200
stefanglase Avatar answered Sep 03 '26 09:09

stefanglase


Consider xdoclet?

XDoclet was really the predecessor to what became annotations in Java 5. It is an open-source code generation library that enables Attribute-oriented programming for Java via insertion of special Javadoc tags. It comes with a library of predefined tags, which simplify coding for various technologies: Java EE, Web services, Portlet etc.

like image 41
Matthew Flynn Avatar answered Sep 03 '26 09:09

Matthew Flynn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!