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

Need to reference String JavaBean from XML Definition of Hibernate SessionFactory

I have a java bean that creates an endpoint: @Bean public String endpoint() { return "jdbc" + "a" + "b" + "c"; } And I want to use that endpoint in my SessionFactory Bean:
Oscar Courchaine
  • 346
  • 3
  • 14
2
votes
2 answers

Programmatically mimick @Bean method to register several instances as beans

(spring boot 1.5, java 8) Suppose there is a Foundation, some Wall types, and Ceilings. They depend on each other, just like their physical counterparts. This configuration class has a Foundation injected and creates Wall beans, so that Ceilings can…
Marnes
  • 651
  • 5
  • 19
2
votes
0 answers

CacheManager Bean Jhipster

I'm new to Jhipster and started to look at it yesterday. It's one thing I don't know how it is working at the moment so I hope I get the answer here. Jhipster creates a UserService which is the service class for managing users. It has a dependency…
2
votes
1 answer

Spring DeferredImportSelector run before any Configurations

I am trying to create something like @Enable... autoconfiguration. I wanted to create such an annotation for a custom library that has an extensive spring config, yet needs like 2 beans supplied, and based on those initializes various contexts. It…
maslan
  • 2,078
  • 16
  • 34
2
votes
1 answer

Spring No bean defined of type AuthenticationManagerBuilder

Lately in my Spring REST API I've encountered a strange exception. Spring tells me that it doesn't find any bean of type org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder It doesn't show up everytime…
Matthieu Meunier
  • 458
  • 5
  • 21
2
votes
2 answers

Spring component initialization by Profile is not working

I have the below class which should be initialized only if active profile is not master. But it is being executed even if the active profile is master. How to implement this? I am using Spring boot and Spring 4. @Component @Scope(value=…
Debopam
  • 3,198
  • 6
  • 41
  • 72
2
votes
2 answers

Better way to register beans in Spring

I am new in Spring. I understand process of Dependency Injection and Inversion Of Control as well. But in few days ago I found one source code which compel me thinking about it. If I am not wrong, Beans can be registered by Stereotype annotations -…
Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
2
votes
0 answers

Spring dynamic bean creation depending on other bean

Is there a way to dynamically create a bean which is dependent on another one? I have a Spring Boot app which loads a configuration.xml file into a configuration bean. I want to have the configuration loaded once I try to create new dynamic beans…
Christina
  • 361
  • 1
  • 5
  • 17
2
votes
1 answer

How to dynamically load jar files with application context by Spring (with no OSGi)?

I am going to create Java Application that can load external jar files at runtime by FileChooser. I am using Spring Framework, and I want to load jar file and its applicationContext.xml file and inject its dependencies dynamically. I tried to…
Xylian
  • 241
  • 2
  • 10
2
votes
1 answer

How to initialize SpringContext once and share across tasks?

I am trying to initialize spring context in my Spark application. I want the context in my slave nodes as well as I want to re-use the beans. Here is the code for the same:- shipperRD2.foreach(shipper->{ AmazonS3 amazonS3Client =…
Sanchay
  • 1,053
  • 1
  • 16
  • 33
2
votes
2 answers

Why spring bean can support not only String[] but also String

This is Spring bean source. @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Bean { @AliasFor("name") String[] value() default {}; @AliasFor("value") …
Smith Cruise
  • 404
  • 1
  • 4
  • 19
2
votes
0 answers

Spring Boot Custom AutoConfiguration and Autowire

I am creating a custom AutoConfiguration for Spring Boot. One of the features I was attempting to create was to create one or more Beans dynamically and adding them to the ApplicationContext at runtime. The problem I ran into was with Autowiring. …
The Architect
  • 75
  • 1
  • 11
2
votes
3 answers

Autowired not working for ConfigurationProperties bean in Spring

I have an application.yml file that has the list of objects as below: outlook: mailboxes: - id: m1 name: mailbox1 - id: m2 name: mailbox2 I have created a spring configuration class called MailBoxProperties to have these…
Ashwini
  • 381
  • 6
  • 23
2
votes
1 answer

Why the concept of starting and stopping beans in spring

There are different ways in which a bean initializaiton/cleanup can be done. Also there are other event mechanisms. Along with all this why does spring have the concept of starting the context which I believe invokes the respective start and stop…
John Eipe
  • 10,922
  • 24
  • 72
  • 114
2
votes
2 answers

Spring - prototype bean inside a singleton bean

Spring has bean types/scopes like -singleton bean (only one bean per application context) -prototype bean (a new bean per request) Now if there is a reference to prototype bean inside a singleton bean, is there a way to get a new prototype bean…
samshers
  • 1
  • 6
  • 37
  • 84