3

I've got the following Spring service:

@Service
public class Worker {

    @Autowired
    private MyExecutorService executor;

    @Autowired
    private IRun run;

    private Integer startingPoint;

    // Remainder omitted

}

Now I want to load the startingPoint through a .properties file.

Is it possible to wire a Spring service through annotations and an xml context at the same time?

Maybe something like this:

<bean id="worker" class="Worker">
    <property name="startingPoint">
        <value>${startingPoint}</value>
    </property>
</bean>

startingPoint is wired through the xml context file, everything else gets auto-wired.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    Just on a side note, it is possible to write a property through an annotation, you can do this with the [@Value annotation](http://stackoverflow.com/questions/317687/inject-property-value-into-spring-bean). –  May 31 '11 at 07:52

1 Answers1

3

Yes! This is most definitely possible, and it's a good way to go if you can't get around using a little bit of XML. Just leave all your annotated fields unspecified, and they'll get injected auto-magically.

Though just to be clear, I believe that you'll have to provide a setter for your Integer field. Spring doesn't want to reach in directly and set fields via the XML descriptor.

stevevls
  • 10,675
  • 1
  • 45
  • 50