spring-bean

How to create Spring Beans in a dynamical way. Using Quartz SchedulerFactoryBean

怎甘沉沦 提交于 2019-12-06 11:14:40
I have a QuartzJobConfig class where I register my Spring-Quartz-Beans . I followed the instruction of the SchedulerFactoryBean , JobDetailFactoryBean and CronTriggerFactoryBean . My Jobs are configured in a yaml file outside the application. Means I have to create the Beans dynamically when the application starts. My Config: channelPartnerConfiguration: channelPartners: - code: Job1 jobConfigs: - schedule: 0 * * ? * MON-FRI name: Job1 daily hotel: false allotment: true enabled: true - schedule: 30 * * ? * MON-FRI name: Job2 weekly hotel: true allotment: false enabled: true ... My Config Class

Does Spring's @RequestScope automatically handle proxying when injected in singleton beans?

人盡茶涼 提交于 2019-12-06 01:52:04
I'm using a Java8/Spring Boot 2 application. I want to inject a request-scoped bean into a singleton bean. The official documentation highlights that either a proxy or ObjectFactory/Provider should be used to ensure always getting the correctly scoped bean at runtime in the singleton bean. However, the @RequestScope annotation seems to "automatically" set some kind of proxy, as explained in the answer to this question . I'm now wondering if the following three implementations are in fact identical and which one is preferred? Approach 1: explicitly using objectFactory<> @Component @RequestScope

Spring can't see beans between servlet-context and contextConfigLocation beans

瘦欲@ 提交于 2019-12-05 06:31:34
I have a spring mvc project set up like so: <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-contexts/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-contexts/configuration-context.xml</param-value> </context-param> It appears if I make a bean in configuration-context.xml and reference a

Can't understand `@Autowired HttpServletRequest` of spring-mvc well

筅森魡賤 提交于 2019-12-05 00:19:09
问题 In our spring application, we use HttpServletRequest in two ways: (the code here are simplied, and seems meaningless) In the controller: @RequestMapping(value = "/hello", method = RequestMethod.GET) @ResponseBody public ResponseEntity<String> hello(HttpServletRequest request) { System.out.println("## controller req.hashcode: " + request.hashCode()); System.out.println("## header 'abc': " + request.getHeader("abc")); return new ResponseEntity<String>("OK", HttpStatus.OK); } In a normal

Spring FactoryBean

随声附和 提交于 2019-12-04 18:38:04
I'm trying to grasp Spring's FactoryBean and I've had and issue. Could you please see my sources below and answer. It's my app context: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

Camel - Passing specific parameters from routes to a generic bean method

不羁的心 提交于 2019-12-04 10:49:45
问题 Let's say I have a Camel route that looks like this : from("direct:myRoute") .setHeader("someHeader", simple("some header value")) .beanRef("myBean", "beanMethod"); And I have a bean that I cannot change that looks like this : public class MyBean { public void beanMethod(String headerExpected) { // do something with the value here. } } Basically, I want to pass the value of someHeader from myRoute to beanMethod within MyBean . Knowing that beanMethod can accept a String , how can I pass the

BeanDefinitionRegistryPostProcessor - How to register a @Configuration class as BeanDefinition and get its @Beans registered as well

放肆的年华 提交于 2019-12-03 20:09:34
Let's suppose I have this @Configuration class: @Configuration public class SomeConfig{ @Bean public MyBean myBean(){ return new MyBean(); } @Bean public Another anotherBean(){ return new AnotherBean(); } } I have a class that implements BeanDefinitionRegistryPostProcessor to add certain BeanDefinition s. On it I also would like to import SomeConfig so that its beans are added to the context: @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { BeanDefinition someConfig= new RootBeanDefinition("x.y.z.SomeConfig"); registry

Copy properties from one bean to another (not the same class) recursively (including nested beans) [duplicate]

谁说我不能喝 提交于 2019-12-03 17:45:32
问题 This question already has answers here : any tool for java object to object mapping? [closed] (9 answers) Closed 4 years ago . Which approach requires the least amount of own written code to achieve a deep copy of one bean to another? The goal is to do it in an automatic way when source and target properties are matched by name. source main bean: public class SourceBean { private String beanField; private SourceNestedBean nestedBean; // getters and setters } source nested bean: public class

Can't understand `@Autowired HttpServletRequest` of spring-mvc well

可紊 提交于 2019-12-03 15:43:55
In our spring application, we use HttpServletRequest in two ways: (the code here are simplied, and seems meaningless) In the controller: @RequestMapping(value = "/hello", method = RequestMethod.GET) @ResponseBody public ResponseEntity<String> hello(HttpServletRequest request) { System.out.println("## controller req.hashcode: " + request.hashCode()); System.out.println("## header 'abc': " + request.getHeader("abc")); return new ResponseEntity<String>("OK", HttpStatus.OK); } In a normal component: @Component class RequestService { private final HttpServletRequest request; @Autowired public

Camel - Passing specific parameters from routes to a generic bean method

醉酒当歌 提交于 2019-12-03 06:33:55
Let's say I have a Camel route that looks like this : from("direct:myRoute") .setHeader("someHeader", simple("some header value")) .beanRef("myBean", "beanMethod"); And I have a bean that I cannot change that looks like this : public class MyBean { public void beanMethod(String headerExpected) { // do something with the value here. } } Basically, I want to pass the value of someHeader from myRoute to beanMethod within MyBean . Knowing that beanMethod can accept a String , how can I pass the value of the header someHeader from the route so that it is accepted as a String within beanMethod ? You