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.

663 questions
12
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
  • 2,676
  • 1
  • 26
  • 49
11
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
  • 135
  • 1
  • 2
  • 8
11
votes
1 answer

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
  • 467
  • 1
  • 5
  • 13
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 { …
Sergey Pauk
  • 4,697
  • 3
  • 25
  • 40
10
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,286
  • 15
  • 56
  • 101
9
votes
4 answers

Create @MockBean with qualifier by annotating class?

In my Spring Boot test I'm using 2 mock beans with different qualifiers: @RunWith(SpringRunner.class) @SpringBootTest class HohoTest { @MockBean @Qualifier("haha") IHaha ahaha; @MockBean @Qualifier("hoho") IHaha ohoho; } Since I'm not using…
maslick
  • 1,712
  • 19
  • 32
9
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
  • 93
  • 1
  • 1
  • 4
9
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
  • 273
  • 1
  • 4
  • 16
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…
galovics
  • 2,884
  • 3
  • 15
  • 25
8
votes
1 answer

Create request scoped beans from a Java 8 Function

Based on this answer I try to configure a request scope bean using java.util.Function interface. My Configuration looks like this: @Configuration public class RequestConfig { @Bean public Function
Patrick
  • 10,322
  • 12
  • 63
  • 100
8
votes
3 answers

Spring overrides bean configuration setting its "Primary" one

Using Spring 3.X.X I have 2 services annotated with @Primary and I created another configuration class where I want to use a "customised" version of one of the services. For some reason I ignore while debugging the configuration class I see that it…
void
  • 1,454
  • 1
  • 14
  • 18
7
votes
2 answers

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

I have a spring mvc project set up like so: appServlet org.springframework.web.servlet.DispatcherServlet
mogronalol
  • 2,819
  • 5
  • 32
  • 54
7
votes
4 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
  • 103
  • 1
  • 5
7
votes
0 answers

Spring beans used in two different scopes

We have a Web Application exposing both Web Resources (REST) and JMS MessageListener. Spring is the framework used to define and inject beans. We defined beans in the scope "request" to store information usable for Web Resources. We would like to…
Blaise Gosselin
  • 506
  • 1
  • 5
  • 6
1
2
3
44 45