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
8
votes
2 answers

Junit 5 test, getting java.lang.IllegalStateException: Test classes cannot include @Bean methods

@ContextConfiguration(classes = ConfigureCustomConfigurationModelProviderTest.class) public class ConfigureCustomConfigurationModelProviderTest extends AbstractContextTest { @Bean(name = "smth") public static…
un1kalny
  • 81
  • 1
  • 6
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,484
  • 1
  • 15
  • 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,946
  • 8
  • 38
  • 56
7
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
  • 12,336
  • 15
  • 73
  • 115
7
votes
2 answers

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

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…
user1884155
  • 3,616
  • 4
  • 55
  • 108
7
votes
2 answers

Spring default bean candidate

I'm writing a library that uses spring, for others to use. In my library, I have class A that has an interface B as a field (with @Autowired). I have a default implementation of that field, but the user can implement a custom implementation by…
Guy Smorodinsky
  • 902
  • 7
  • 16
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
  • 7
7
votes
1 answer

Spring Bean Inheritance Using Annotations Bean reference back issue

I want to initialise classes which are inherited using spring Bean. I have followed this stackoverflow question to implement inheritance Spring Inheritance - Annotation but I am getting exception This is my parent class public class…
Bilal Shah
  • 1,135
  • 7
  • 17
  • 42
7
votes
1 answer

Spring does class have to be component to AutoWire a property in it?

In Spring 3.X does a class have to be annotated as component in order to Autowire a field into it? Let's say I have: @Service("myBean") public class Mybean { } public class Target { @Autowired @Qualifier("myBean") private…
Adam Bronfin
  • 1,209
  • 3
  • 27
  • 43
7
votes
0 answers

Define bean aliases programmatically with spring java config

We have several DB connections in our application and therefore several configs for JPA. The configs only differ in things like schema name, DB hostname etc. The rest like hibernate setup etc. is (normally) the same. This results in multiple…
James
  • 11,654
  • 6
  • 52
  • 81
7
votes
4 answers

Spring lazy loading - loading one bean loads all @Lazy beans of that class

I've declared two beans of same class type. Initialized them to be @Lazy. @Autowiring one bean of them automatically initialized the other bean as well. I was surprised to see that behavior. Just curious to know more about the…
phanin
  • 5,327
  • 5
  • 32
  • 50
6
votes
2 answers

Aliasing a bean outside the bean definition using Java config in Spring Boot

How to alias a bean outside the bean definition using Java config in Spring Boot?
Prajwel
  • 97
  • 7
6
votes
2 answers

How to do deep copy of inner objects from Hibernate Entity to DTO?

I have entity class public Class StudentEntity{ private int id; private String name; private AddressEntity address; private ProfileEntity profile; //getter setter } public Class StudentDTO{ private int id; private String…
Shakthi
  • 826
  • 3
  • 15
  • 33
6
votes
1 answer

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

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(); …
codependent
  • 23,193
  • 31
  • 166
  • 308
6
votes
1 answer

Java & Spring Bean: Create a bean with multiple Generic Types

There is a class with 2 Generic Types. public class GenericDao implements IGenericDao { ... } I need to initiate it from spring.
ufukgun
  • 6,889
  • 8
  • 33
  • 55
1 2
3
51 52