autowired

How to autowire @ConfigurationProperties into @Configuration?

假如想象 提交于 2019-12-19 09:23:48
问题 I have a properties class defined like this: @Validated @ConfigurationProperties(prefix = "plugin.httpclient") public class HttpClientProperties { ... } And a configuration class like this: @Configuration @EnableScheduling public class HttpClientConfiguration { private final HttpClientProperties httpClientProperties; @Autowired public HttpClientConfiguration(HttpClientProperties httpClientProperties) { this.httpClientProperties = httpClientProperties; } ... } When starting my spring boot

Spring @Autowired in Servlet

牧云@^-^@ 提交于 2019-12-19 08:08:22
问题 I am using Spring framework (2.5.4) in my app with Load time weaving and everything works fine everywhere (in Spring beans, in non-Spring entities), except when I try to autowire field in a servlet annotated as @Configurable, then I get a nice NullPointerException... @Configurable(dependencyCheck=true) public class CaptchaServlet extends HttpServlet{ @Autowired private CaptchaServiceIface captchaService; @Override public void init(ServletConfig config) throws ServletException { super.init

Spring @Autowired in Servlet

偶尔善良 提交于 2019-12-19 08:07:24
问题 I am using Spring framework (2.5.4) in my app with Load time weaving and everything works fine everywhere (in Spring beans, in non-Spring entities), except when I try to autowire field in a servlet annotated as @Configurable, then I get a nice NullPointerException... @Configurable(dependencyCheck=true) public class CaptchaServlet extends HttpServlet{ @Autowired private CaptchaServiceIface captchaService; @Override public void init(ServletConfig config) throws ServletException { super.init

Autowiring :expected at least 1 bean which qualifies as autowire candidate for this dependency

旧时模样 提交于 2019-12-19 07:22:04
问题 Okay, I know that there are many questions asked around the same topic. But I cant seem to make anything work. It also might be the case that I am yet to completely understand the auto wiring concept. My Problem: I am able to get to the required page, but whenever I click on the any button to perform an action I get Null pointer exception which seems obvious as I dont think spring is able to properly map the bean needed. So, when I add @autowired=true , it gives me the above given exceptionn.

How to set @Autowired constructor params as “required=false” individually

倖福魔咒の 提交于 2019-12-18 18:35:09
问题 I'm using the @Autowired annotation under a @Configuration class constructor. @Configuration public class MyConfiguration { private MyServiceA myServiceA; private MyServiceB myServiceB @Autowired public MyConfiguration(MyServiceA myServiceA, MyServiceB myServiceB){ this.myServiceA = myServiceA; this.myServiceB = myServiceB; } } As the Spring documentation sais, I'm able to declare whether the annotated dependency is required. If I mark the @Autowired annotation under the constructor as

Singleton and @Autowired returning NULL

主宰稳场 提交于 2019-12-18 15:17:24
问题 I have a repository manager that manages my repositories. I have the @Autowired to instantiate my properties, but they are always null. The beans are correctly configured in my xml. Any reason why? public class RepositoryManager { private static RepositoryManager instance; private RepositoryManager() { } public static RepositoryManager Instance() { if(instance == null) instance = new RepositoryManager(); return instance; } @Autowired private IUserRepository userRepository; @Autowired private

@Autowired vs @Required on setter

匆匆过客 提交于 2019-12-18 13:55:23
问题 I'm curious to know what's the difference between code like this: class MyClass { @Autowired MyService myService; } and code like this: class MyClass { MyService myService; @Required public void setMyService(MyService val) { this.myService = val; } } 回答1: @Autowired annotation is used when you want to autowire a bean. @Autowired is not limited to setter. It can be used with a constructor and a field as well. If you use @Autowired annotation on a field, that field will be autowired with bean

What is the spring way to autowire factory created instances?

和自甴很熟 提交于 2019-12-18 13:37:43
问题 I have a controller which is supposed to create version dependend instances (currently not implemented). @Controller public class ReportController { @Autowired private ReportCompFactory reportCompFactory; public ModelAndView getReport() { I_Report report = reportCompFactory.getObject(); ^^^^^<- no autowiring in this instance } ... } The Factory looks like this: @Component public class ReportCompFactory implements FactoryBean<I_Report> { @Override public I_Report getObject() throws

What is the spring way to autowire factory created instances?

↘锁芯ラ 提交于 2019-12-18 13:37:06
问题 I have a controller which is supposed to create version dependend instances (currently not implemented). @Controller public class ReportController { @Autowired private ReportCompFactory reportCompFactory; public ModelAndView getReport() { I_Report report = reportCompFactory.getObject(); ^^^^^<- no autowiring in this instance } ... } The Factory looks like this: @Component public class ReportCompFactory implements FactoryBean<I_Report> { @Override public I_Report getObject() throws

Spring Autowiring stopped working on GAE

大兔子大兔子 提交于 2019-12-18 09:39:11
问题 I'm sure my app worked right until yesterday, when I got this error: Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@1079ff{/,/ base/data/home/apps/s~trewnewmedia/1.357617962256387950} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scadenziarioController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public