autowired

Inject bean into enum

陌路散爱 提交于 2019-12-28 02:39:19
问题 I have the DataPrepareService that prepare data for reports and I have an Enum with report types, and I need to inject ReportService into Enum or have access to ReportService from enum. my service: @Service public class DataPrepareService { // my service } my enum: public enum ReportType { REPORT_1("name", "filename"), REPORT_2("name", "filename"), REPORT_3("name", "filename") public abstract Map<String, Object> getSpecificParams(); public Map<String, Object> getCommonParams(){ // some code

Spring component-scan without autowiring?

微笑、不失礼 提交于 2019-12-25 18:47:14
问题 Does it makes sense to use component-scan WITHOUT using autowiring on spring? I like the idea of having component scan on an MVC environment for controllers, hell I even like to avoid declaring all the DAOs, Services ... on the xml. However I am not a big fan of autowiring, so, would it still be possible to manually inject the desired beans using the xml config file or is it just a non-sense? UPDATE : What would be the advantage of using @Autowired instead of explicit declaration via XML

Spring @Bean at method returning already created bean

人走茶凉 提交于 2019-12-25 18:32:21
问题 I have below class StaticDataCachesServerBean which is autowired by it's interface i.e. @Autowired private StaticDataCaches staticDataCaches; in some another class I already created instance of sdcAutoAssignmentRuleCache in init method of StaticDataCachesServerBean class. As per my understanding if annotate sdcAutoAssignmentRuleCache with @Bean won't make any impact as instance is already created and same is returned when method is called. Is my understanding correct? What will happen if I

Can I use Spring @Autowired in multiple classes?

ぐ巨炮叔叔 提交于 2019-12-25 16:45:21
问题 My question is - Can I autowire an instance of a class in multiple classes? My application uses Spring MVC to communicate between the JSP front end pages and my MongoDB back end. I am using MongoDB for my repository. I have created a service which performs the CRUD methods for MongoDB. This can be seen below with one of the CRUD methods (not all are shown as they are not needed). It uses the Mongo template. import org.springframework.beans.factory.annotation.Autowired; import org

Spring 4 autowiring of generic classes works in test, doesn't work when deployed to server

♀尐吖头ヾ 提交于 2019-12-25 06:46:50
问题 I have generic classes which autowires dependencies based on their generic type like this: public abstract class GenericRestService<C extends AbstractTenantEntity> extends RestResource<C> { protected final Logger log; @Autowired(required = false) protected GenericResourceService<C> service; @Autowired(required = true) protected JpaRepository<C, Long> repo; // Now use service if one with specified generic type C is found, otherwise use repo In my spring tests everything works: if no

How to use autowiring and package as a jar

a 夏天 提交于 2019-12-25 04:16:09
问题 I am trying to build a core-services jar, where I am making use of @Component, @Service and @Autowired annotations to autowire beans. I am packaging as a simple jar. How do I use the beans of this jar to autowire in another spring-boot application which uses core-services jar as a pom dependency? 回答1: Once you add them as your pom dependencies, you can configure them so that they will get court to your @ComponentScan So in your Final application @SpringBootApplication @ComponentScan

@Autowiring not working at Field Level

别说谁变了你拦得住时间么 提交于 2019-12-25 03:55:29
问题 @Autowiring is not working on fields and am getting: Error: SEVERE: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService net.viralpatel.contact.controller.ContactController.contactService; nested exception is org

Spring + Hibernate + Maven NoSuchBeanDefinitionException

拜拜、爱过 提交于 2019-12-25 03:41:05
问题 This question is an evolution of Spring + Hibernate + Maven org.hibernate.MappingException: AnnotationConfiguration instance is required that. My current log is: log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [config.xml]: Cannot

spring autowiring with processInjectionBasedOnCurrentContext(this);

前提是你 提交于 2019-12-25 01:18:27
问题 I have following situation. There is POJO which has autowired implementation of an interface, using some spring magic as shown bellow. However this dependency doesn't get resolved if creation of channels is managed via spring bean. It only works if POJO factory creates channels. Example bellow. @Controller public class Test{ @RequestMapping(value = "/load", method = RequestMethod.GET) public @ResponseBody String testConfiguration() { // this is pojo and here it works, channels within have

Spring Boot Autowiring of JsonDeserializer in Integration test

守給你的承諾、 提交于 2019-12-24 16:15:54
问题 I have an application which needs a service to be Spring wired in a JsonDeserializer. The problem is that when I start up the application normally it is wired, but when I start it up in a test, it is null. The relevant code is: JSON Serializer/Deserializer: @Component public class CountryJsonSupport { @Component public static class Deserializer extends JsonDeserializer<Country> { @Autowired private CountryService service; @Override public Country deserialize(JsonParser jsonParser,