Questions tagged [spring-bean]

A simple JavaBean managed by the Spring IoC container.

A simple JavaBean managed by the Spring IoC container. These beans are created with the configuration metadata that is supplied to the container, for example, in the form of XML <bean/> definitions or @Bean annotation. Actually, the BeanFactory is the main IoC container which instantiates, configures, and manages these beans. These beans typically have associations with each other, and therefore have dependencies between themselves. These dependencies are configured in the configuration files used by the BeanFactory. Other dependencies that are invisible from the configuration file could be a function of programmatic interactions between beans at run-time.

767 questions
15
votes
2 answers

how to get multiple instances of same bean in spring?

By default, spring beans are singletons. I am wondering if there is a way to get multiple instances of same bean for processing. Here is what I do currently @Configuration public class ApplicationMain { @Value("${service.num: not…
brain storm
  • 30,124
  • 69
  • 225
  • 393
15
votes
1 answer

Dynamically add new queues, bindings and exchanges as beans

I'm currently working on a rabbit-amqp implementation project and use spring-rabbit to programmatically setup all my queues, bindings and exchanges. (spring-rabbit-1.3.4 and spring-framework versions 3.2.0) The declaration in a javaconfiguration…
JustinV
  • 165
  • 1
  • 6
14
votes
2 answers

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

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 :…
abbasdgr8
  • 555
  • 1
  • 5
  • 15
13
votes
3 answers

Spring Bean Alias in JavaConfig

I have a @Service annotated class which provides core functionality which I can use in all my projects: @Service public class MyService {} and another one which extends it to implement project specific stuff: @Service public class ExtendedMyService…
dtrunk
  • 4,685
  • 17
  • 65
  • 109
13
votes
1 answer

Not loading a Spring bean when a certain profile is set

Background: So, I've got several beans that interface external systems. For development, it's convenient to mock the external systems and replace the interfacing beans with some implementations that produce more or less static responses. So what…
ZeroOne
  • 3,041
  • 3
  • 31
  • 52
12
votes
1 answer

How to inject RestTemplate

I am not using xml configurations to define beans. Instead using component scanning and autowire to define and inject dependencies. RestTemplate is part of springframework. How can I inject this class ?
Ravi
  • 323
  • 2
  • 6
  • 18
12
votes
2 answers

Spring annotation conditionalOnBean not working

I defined a class with annotation Configuration @Configuration @AutoConfigureAfter(EndpointAutoConfiguration.class) public class EndpointConfiguration { @Resource private MetricsEndpoint metricsEndpoint; @Bean …
zhangzhide
  • 145
  • 1
  • 2
  • 8
11
votes
3 answers

Field jdbcTemplate required a bean of type 'org.springframework.jdbc.core.JdbcTemplate' that could not be found

I made this simple application to connect to the MySQL database and I'm getting this error: org.springframework.jdbc.core.JdbcTemplate In my configuration (com.kubamadry.dao.MySqlStudentDao): ***************************** APPLICATION FAILED TO…
Kuba Madry
  • 113
  • 1
  • 1
  • 6
10
votes
5 answers

Spring/Spring bean configuration file option is missing in STS

I am just following a tutorial , where in I need to add a spring configuration file but I don't see spring / Spring bean configuration file option in Spring Tool Suite 4 (Version: 4.0.1.RELEASE), could somebody help me where to find that option As…
Ravi kiran
  • 135
  • 1
  • 1
  • 6
10
votes
3 answers

Cleanly destroy Spring Application Context

I have been running in to problems making sure that a spring application context that i am destroying has completely gone away, and cant see the object being garbage collected. When i look at the instance in VisualVM i can see that there are a…
Mike
  • 111
  • 1
  • 4
10
votes
4 answers

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

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 { …
S. Pauk
  • 5,208
  • 4
  • 31
  • 41
9
votes
2 answers

Java 11 - Replace Spring @PostConstruct with afterPropertiesSet or using initMethod

I'm using spring applications which sometimes uses @PostConstruct for setup in code and tests It seems that annotation will be excluded from Java 11: Note that both @PostConstruct and @PreDestroy annotations are part of Java EE. And since Java EE…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
9
votes
2 answers

Spring bean lazy initialization

I was thinking about the lazy-initialization of beans in Spring. For me, it wasn't crystal clear that the "lazy" here means that a bean will be created when it's referenced. I expected that the lazy initialization support in Spring is different. I…
Arnold Galovics
  • 3,246
  • 3
  • 22
  • 33
8
votes
2 answers

When to implement WebMvcConfigurer to configure Spring MVC?

I'm learning about Spring MVC with Java configuration (no xml) and I have a simple question. I see 2 approaches of making Spring bean configuration: approach 1: @Configuration @EnableWebMvc @ComponentScan(basePackages="com.demo.springmvc") public…
user9608350
8
votes
2 answers

ContextSingletonBeanFactoryLocator alternative in spring 5

We were using 4.2.x version of spring and we are using ContextSingletonBeanFactoryLocator to load bean like below BeanFactoryLocator bfLocator =…
Dheeraj Joshi
  • 3,057
  • 8
  • 38
  • 55
1
2
3
51 52