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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.