spring-bean

Is there a way to @Autowire a bean that requires constructor arguments?

半腔热情 提交于 2019-11-26 17:12:35
I'm using Spring 3.0.5 and am using @Autowire annotation for my class members as much as possible. One of the beans that I need to autowire requires arguments to its constructor. I've looked through the Spring docs, but cannot seem to find any reference to how to annotate constructor arguments. In XML, I can use as part of the bean definition. Is there a similar mechanism for @Autowire annotation? Ex: @Component public class MyConstructorClass{ String var; public MyConstructorClass( String constrArg ){ this.var = var; } ... } @Service public class MyBeanService{ @Autowired MyConstructorClass

How to reinitialize a Spring Bean?

大憨熊 提交于 2019-11-26 17:06:55
问题 Is it possible to reinitialize a Spring Bean on runtime? My Bean uses static settings which in some cases changes and then i have to reinitialize the bean. 回答1: You have three options to update singleton bean in spring context, you can chose one suitable for your use case: Reload method In the Bean Create a method in your bean which will update/reload its properties. Based on your trigger, access the bean from spring context, and then call the reload method to update bean properties (since

Is there a way to @Autowire a bean that requires constructor arguments?

别等时光非礼了梦想. 提交于 2019-11-26 05:18:22
问题 I\'m using Spring 3.0.5 and am using @Autowire annotation for my class members as much as possible. One of the beans that I need to autowire requires arguments to its constructor. I\'ve looked through the Spring docs, but cannot seem to find any reference to how to annotate constructor arguments. In XML, I can use as part of the bean definition. Is there a similar mechanism for @Autowire annotation? Ex: @Component public class MyConstructorClass{ String var; public MyConstructorClass( String