autowired

Autowire in deserialization class

陌路散爱 提交于 2019-12-11 02:28:43
问题 How to autowire inside deserialization class? Here is the mapping class: @Component @JsonIgnoreProperties(ignoreUnknown = true) @JsonNaming(PropertyNamingStrategy.PascalCaseStrategy.class) public class Container { @Autowired private CalcResourceUsage calcResourcePercentage; private ContainerStats containerStats; @Autowired private AverageResourceUsage averageResourceUsage; public Container(){ SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); } private String Id; private

Symfony 4 argument has no type-hint, you should configure its value explicitly

百般思念 提交于 2019-12-11 02:27:39
问题 Symfony 4.2.3 Recently upgraded from version 3.4 to 4.2.3 and got my project working, but when setting autoconfigure in services.yaml to true, I will receive this error message: Cannot autowire service "App\EventListener\RedirectToLocaleActiveListener": argument "$localeActive" of method "__construct()" has no type-hint, you should configure its value explicitly. My services.yaml parameters: locale: de locale_active: de app_locales: de|en uploads_directory_name: uploads uploads_profile

Inject a new instance of an object into each request handler

*爱你&永不变心* 提交于 2019-12-11 01:58:36
问题 I have a lot of Spring RestControllers with methods annotated with RequestMapping . I now would like to inject a custom object into these RequestMapping methods, and create an custom instance for each request. I would like to write something like the following: @RequestMapping("/search") public SomeReturnObject foobar(@RequestParam("query") String query, MyRequestFoo foo) { // ... } Now I would like to create a mechanism, where each call to that method (i.e. each request) get a new instance

How to use autowired (@Autowired) references from main(String[] args) method?

狂风中的少年 提交于 2019-12-11 01:44:20
问题 I am trying to use an autowired reference from main class and am facing : Cannot make a static reference to the non-static field zipCodeLookupService. This is obvious. But I want to know how to handle this situation. What is the correct way of autowiring when main class is involved. My code will be as below - Interface class package com.example.services; public interface IZipCodeLookup { String retriveCityForZip(String zipCode); } Service Class package com.example.services; import org

Problems with @Autowire annotation (null)

依然范特西╮ 提交于 2019-12-10 21:00:06
问题 I have problems with two services that i autowired in a validator class. The services works ok because in my controller are autowired. I've an applicationContext.xml file and MyApp-servlet.xml file. My base package is es.unican.meteo and i have problems with the package es.unican.meteo.validator. The package es.unican.meteo.controller and es.unican.meteo.service can autowire the services properly. applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www

JavaMailSenderImpl autowire error if spring.mail.host not in application.properties

假如想象 提交于 2019-12-10 19:29:02
问题 I am having a little "problem" using JavaMailSenderImpl to send emails in my spring boot application. I am trying to set all properties dynamically (I will want them to be read from the DB in the future) but, for reasons unknown to me, autowiring JavaMailSenderImpl only works if "spring.mail.host" is present in my application.properties. It doesn't matter the value I set (it can be empty, it doesn't matter because I set the right one later), but the property must be there or autowiring will

Spring: injecting @RequestBody into @Bean

人盡茶涼 提交于 2019-12-10 17:07:31
问题 I want to populate requestScopedBean.userDetails when my controller's update(...) gets executed / before it is executed. In my spring web project I have java based MyConfiguration extends WebMvcConfigurerAdapter in which I have: @Bean(name = "requestScopedBean") @Scope(value = "prototype") public RequestScopedBean requestScopedBean() { return new RequestScopedBean(); } While in RequestScopedBean.java : public class RequestScopedBean { public @Autowired UserDetails userDetails; public void

Spring Javaconfig based autowire by name not working

久未见 提交于 2019-12-10 17:07:12
问题 I am trying to use Javaconfig based Spring configurations. I have two beans of same type and trying to autowire them by Qualifier. But it does not seems to working. This is my Configuration class @Configuration @EnableAutoConfiguration @ComponentScan("com.test") public class BasicConfig { @Bean(name = "mysqlSource") @Qualifier("mysqlSource") public DataSource jdbcTemplateMySql() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver");

Proper way of autowiring shared queue in Spring

女生的网名这么多〃 提交于 2019-12-10 15:15:52
问题 I've got kind of producer-consumer pattern implemented in my application. On one end producer pushes entities to process recieved from different sources, on the other hand I've got consumer which take this events out of the queue and process them. Both producer and consumer are spring beans and discovered automatically and both require link to this shared Queue. I know that I can define my beans in either xml file or Java configuration and pass this Queue as parameter as constructor argument

SpringBoot Junit bean autowire

↘锁芯ラ 提交于 2019-12-10 14:03:24
问题 I try to write junit test to my service. I use in my project spring-boot 1.5.1. Everything works fine, but when I try to autowire bean (created in AppConfig.class), it gives me NullPointerException. I've tried almost everything. This is my configuration class: @Configuration public class AppConfig { @Bean public DozerBeanMapper mapper(){ DozerBeanMapper mapper = new DozerBeanMapper(); mapper.setCustomFieldMapper(new CustomMapper()); return mapper; } } and my test class: @SpringBootTest public