Reputation: 2549
I'm working on some old code base and it's using xml configuration.
Basically it has a basic controller named BaseController
and all other controllers inherit that. Now I need to add an extra service bean which all current controllers need to use. The bean definition is like this:
<bean id="myService" class="com.myweb.MyService" scope="singleton"/>
The base controller will also have a field named MyService myService
, with a null value now.
Instead of setting the property name in the xml file under each existing controller bean mapping (there are too many), how can I set the singleton MyService instance to all controllers at runtime (like a default value instead of null)?
Upvotes: 0
Views: 137
Reputation: 280168
You can autowire the bean.
Annotate your BaseController
MyService
field with
@Autowired
private MyService myService;
Upvotes: 1