autowired

Inject primitive properties to Spring bean when using @Autowired?

笑着哭i 提交于 2020-01-24 00:58:07
问题 try to inject myInt of the following through Spring public class MyBean { @Resource (name="myValue") private int myInt; Any idea? I have got the following post. But it don't work for me. I still get the following error message. Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myValue' must be of type [int], but was actually of type [java.lang.Integer] Detail: The following is the test servlet that I

How does Spring framework autowire a collection

↘锁芯ラ 提交于 2020-01-23 07:14:09
问题 I've never seen an autowired collection: @Service public class SomeFactory { @Autowired private List<Foo> foos; @PostConstruct public void init() { for(Foo foo: foos) { //do something } } } In init() method, I can see foos has several entries already. I guess Spring knows who's supposed to be the entry of foos. But, how? What should I do if I want to add a Foo object into foos? Need to configure in a property file, or any other idea? 回答1: Spring's BeanFactory is basically a registry of beans.

Symfony 3.3 services autoconfiguration

限于喜欢 提交于 2020-01-22 20:08:02
问题 I'm trying migrate to symfony 3.3 and use new feature autowire / autoconfigure services: So in services.yml i have: services: _defaults: autowire: true autoconfigure: true public: false # makes classes in src/AppBundle available to be used as services AppBundle\: resource: '../../src/AppBundle/*' # you can exclude directories or files # but if a service is unused, it's removed anyway exclude: '../../src/AppBundle/{Entity,Controller,DQL,Form/DataTransformer,Repository}' i declare my twig

Why is my @Autowired object null?

最后都变了- 提交于 2020-01-21 20:08:47
问题 I've the below JSF managed bean: package com.example; import java.io.Serializable; import javax.faces.bean.ManagedBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component @ManagedBean public class Bean implements Serializable { @Autowired private SomeService someService; public void update() { someService.update(someEntity); } // ... } And the below Spring service: @Transactional @Repository public class SomeService {

Why is my @Autowired object null?

孤街醉人 提交于 2020-01-21 20:08:23
问题 I've the below JSF managed bean: package com.example; import java.io.Serializable; import javax.faces.bean.ManagedBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component @ManagedBean public class Bean implements Serializable { @Autowired private SomeService someService; public void update() { someService.update(someEntity); } // ... } And the below Spring service: @Transactional @Repository public class SomeService {

In Spring, can I autowire new beans from inside an autowired bean?

自作多情 提交于 2020-01-21 03:24:05
问题 I normally just @Autowire things into spring objects. But I've encountered a situation where I need to dynamically create some objects which require values that could be autowired. What should I do? What I could do is just manually pass the autowired values into the constructor of the new objects. What I would like to do is just autowire each new object as I create it. @Service public class Foo { @Autowired private Bar bar; /** This creates Blah objects and passes in the autowired value. */

Scheduled Tasks in Liferay with Autowired

佐手、 提交于 2020-01-17 01:41:56
问题 im trying to create scheduled task in liferay portlet. Liferay: 6.2 Spring: 3.1.4.RELEASE With <scheduler-entry> <scheduler-description>test-scheduler</scheduler-description> <scheduler-event-listener-class> project.ScheduledProcesser </scheduler-event-listener-class> <trigger> <simple> <simple-trigger-value> 1 </simple-trigger-value> <time-unit>minute</time-unit> </simple> </trigger> </scheduler-entry> and the corrensponding class @Component public class ScheduledProcesser implements

Changing Autowired bean type unexpectedly changes value?

*爱你&永不变心* 提交于 2020-01-16 00:43:35
问题 I've tried to create an Application and ran into some funky behavior. First, I'll run through my setup. Here's my configuration class: ProblemApp.java @SpringBootApplication public class ProblemApp { public static void main(String[] args) { var context = SpringApplication.run(ProblemApp.class); var tblController = context.getBean(TableController.class); tblController.printTable(); } @Bean public TableController getTableController() { return new TableController(); } @Bean("componentTable")

Spring: create LocalDate or LocalDateTime from @Value parameter

限于喜欢 提交于 2020-01-14 13:13:44
问题 In a spring project, I'd like to create a LocalDate from an @Autowire d constructor parameter whose value is in a .properties file. Two things I'd like to do: If the property file contains the property my.date , the parameter should be created by parsing the property value When the property is set, and when I use the following: @DateTimeFormat(pattern = "yyyy-MM-dd") @Value("${my.date}") LocalDate myDate, ... I get this error: java.lang.IllegalStateException: Cannot convert value of type

Converting spring xml to java configuration with implicit setter autowiring and ComponentScan

南楼画角 提交于 2020-01-13 07:05:31
问题 I have two classes: vehicle.Tire and vehicle.Car. package vehicle; @Named public class Tire { private String age; } package vehicle; @Named public class Car { private Tire tire; // Spring calls this setter because default-autowire="byName" of xml configuration public void setTire(Tire newTire) { this.tire = newTire; } public Tire getTire() { return this.tire; } } The following spring xml works fine. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001