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
5
votes
1 answer

Equivalent of org.springframework.boot.context.embedded.FilterRegistrationBean for non-Boot Spring project?

I'm trying to implement external session handling in Spring, as per this tutorial. I'm having some trouble adding the right filter though. Spring Boot appears to have defined the proper bean/filter, but my project is not Spring Boot, so it cannot…
Joseph Blair
  • 1,385
  • 2
  • 12
  • 25
5
votes
1 answer

Spring: how to initialize related lazy beans after main bean creation

I have code with lazy initialized beans: @Component @Lazy class Resource {...} @Component @Lazy @CustomProcessor class ResourceProcessorFoo{ @Autowired public ResourceProcessor(Resource resource) {...} } @Component @Lazy…
mitallast
  • 183
  • 2
  • 8
4
votes
1 answer

Custom Spring @Scope for each tenant

I am implementing an application which is to support multiple tenants (users) within it. Each tenant makes use of a 3rd party service (API), although with different authentication credentials. The approach I have in mind for this is that of…
Kanghu
  • 561
  • 1
  • 10
  • 23
4
votes
3 answers

Java spring noob beans and configuration

I'm trying to run the fallowing classes. package com.example.demo; import org.apache.catalina.core.ApplicationContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import…
user1934513
  • 693
  • 4
  • 21
4
votes
1 answer

How can I achieve annotation-based collection merging in Spring?

I am trying to initialize a Spring component with a set of all beans of a certain type (well really, anything I can iterate). The Spring core documentation talks about collection merging, but only in the context of annotation-based…
Michael
  • 41,989
  • 11
  • 82
  • 128
4
votes
3 answers

Is a spring bean created with NEW really a singleton

I created a spring bean in a configuration class like this: @Bean MyClass getMyClass() { MyClass mc = new MyClass() return mc; } Whenever MyClass is autowired in another class that needs it injected, will it always create a new object by…
Hary
  • 1,127
  • 4
  • 24
  • 51
4
votes
2 answers

What's the difference between @Lazy annotation and lazy-init attribute of tag?

As per my understanding, @Lazy annotation and lazy-init attribute of tag should have the same functionality. But when I developed the following code, it's showing distinct behaviours. In the following code, I was expecting :- (Circular Dependency…
4
votes
3 answers

how @bean and @Autowired actually works?

My configuration: @Autowired private PasswordEncoder passwordEncoder; @Bean public PasswordEncoder passwordEncoderBean() { return new BCryptPasswordEncoder(); } @Bean @Override public AuthenticationManager…
chandrakant
  • 370
  • 3
  • 25
4
votes
0 answers

spring bean validation is slow for derived classes

If I have a base class like this public class ValidDemo { @Size(min = 1, max = 100) private String field1; @Size(min = 1, max = 100) private String field2; @Size(min = 1, max = 100) private String field3; @Size(min = 1, max = 100) private String…
4
votes
1 answer

I would like to get advice on Spring BeanCreationException Error

This is the person who asked the question just before. The error on the question was successful, but I was faced with another error. As a beginner in Spring, there are many things I don't know and I have a lot of questions to ask. Please…
4
votes
2 answers

Spring boot - @Component Annotation creates two beans of same type

When I add the @Component annotation to a class, it creates two beans of the same type (class type) and I get an error that there is no unique bean identifier. But when I remove the @Component annotation, I only get one bean. I don't see where the…
Kingamere
  • 9,496
  • 23
  • 71
  • 110
4
votes
3 answers

Spring-integration gateway cannot be autowired, no qualifying bean found

I am trying to send the output from a spring batch process to RabbitMQ. To avoid hard dependency on Rabbitmq, I used spring-integration as suggested in Is there an API in spring-xd to write to a message bus?. I had everything working fine with…
Alice
  • 95
  • 4
  • 12
4
votes
3 answers

How to make the Spring bean singleton in distributed environment?

I am learning Spring, and I know that bean will be by default singleton in one application context.But what if we deploy the applications in distributed system? What will be the practical way to achieve singleton since every time a request comes in,…
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149
4
votes
2 answers

Weak requirements: how to make sure an object is initialized

I want to write bean-friendly classes. I have observed a tendency (mostly with beans) to move required parameters to setters from the constructor (and use an init() method when done setting up the initial state). This method concerns me because I…
vbence
  • 20,084
  • 9
  • 69
  • 118
4
votes
0 answers

play.data.Form understanding subclassing in Java play framework

I would like to use the play.data.Form feature of Play!Framework but I am having a problem with the following classes. Could anybody tell me if there is a way to make the Forms aware of nested paths with such inheritance structures? So far what I…
le-doude
  • 3,345
  • 2
  • 25
  • 55