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

Accessing spring loaded properties in BeanDefinitionRegistryPostProcessor

How can I access properties loaded by in BeanDefinitionRegistryPostProcessor.postProcessBeanDefinitionRegistry. I am unable to use fields annotated with @Value, as they do not seem to be initialized (their values are…
Mukund Jalan
  • 1,145
  • 20
  • 39
3
votes
1 answer

Java based Logback Configuration

I got stuck with java based logback configuration via beans. As observed, the configuration is not even loading. Would be great if anybody can guide me to make it resolved. Attaching the code below. public class…
3
votes
1 answer

Get a bean (programmatically registered) from Spring context?

I registered a bean programmatically: @Autowired private GenericApplicationContext applicationContext; [...] applicationContext.registerBean("a0", A.class, () -> new A(0)); // make sure to set up the bean applicationContext.getBean("a0"); When I…
Jonathan
  • 127
  • 1
  • 11
3
votes
3 answers

How to provide a parameterized component in Spring?

Currently, I have a component that implements CommandLineRunner and parses the command line arguments with Commons CLI. java -jar app.jar --host 123.123.222 --port 8080 There is also another component, Requester, which depends on (a subset of)…
mike
  • 4,929
  • 4
  • 40
  • 80
3
votes
2 answers

ClassCastException: com.sun.proxy.$ProxyX cannot be cast to a class

I have a Spring bean (ChildBean extends Parent) which is extending an abstract class (Parent implements Runnable). public abstract class Parent implements Runnable { public final void run() { // some code } public int…
sys463
  • 337
  • 2
  • 5
  • 18
3
votes
3 answers

Issue with Spring AOP and Final class throwing "Could not generate CGLIB subclass"

1) Below is the small project I have where I do want logging with SpringAOP. Using spring-aop-4.1.6.RELEASE.jar and below is LoggingAspect.java with few point cuts. package com.myprj.aop.aspect; import org.apache.commons.logging.Log; import…
user1876040
  • 431
  • 1
  • 7
  • 18
3
votes
3 answers

Accessing Spring ApplicationContext inside of BeanDefinitionRegistryPostProcessor

How does one access the ApplicationContext inside of a BeanDefinitionRegistryPostProcessor(BDRPP)? I have the following BDRPP. public class MyCustomBeansFactoryPostProcessor implements BeanDefinitionRegistryPostProcessor { @Override public void…
Neo
  • 4,640
  • 5
  • 39
  • 53
3
votes
1 answer

How to skip the failed beans in springboot to avoid reportFailure:771 >> Application startup failed

Is there any way to skip the failure bean to avoid application startup failed.Let me explain the scenario. I am creating hazlecast bean on application startup.sometime hazecast server might be not alive.In that time when i am starting the springboot…
RathanaKumar
  • 325
  • 4
  • 14
3
votes
1 answer

@Bean initialization - difference between parameter injection vs. direct method access?

If a service bean depends on another: is there any difference between injecting that bean as a method parameter, or fetching from the method reference directly? @Configuration public class MyConfig { @Bean public SomeService some() { …
membersound
  • 81,582
  • 193
  • 585
  • 1,120
3
votes
0 answers

spring load dynamically beans from xml which use property injection

I need to load bean definitions from XML. The file is in a remote location (http) which is configured by properties. The properties should also be loaded from a remote location (a spring cloud config server) constraints: Spring 4.3.14 (not…
Yoni
  • 375
  • 3
  • 19
3
votes
0 answers

Combining Spring constructor dependency injection with simple argument

I have a prototype bean that autowires a bean in the constructor: @Component @Scope("prototype") public class MyClass { // Autowired annotation not needed in Spring 5 public MyClass(UserRepository userRepository) { } } This bean is…
BigJ
  • 1,990
  • 2
  • 29
  • 47
3
votes
1 answer

spring-integration-mqtt With multiple Mqtt Servers for subscription

I am using Spring's spring-integration-mqtt and i can connect to a single Mqtt server and can receive messages on subscribed topics , and now i want to make application which can connect to multiple Mqtt Servers and can receive data from every…
Rawat
  • 461
  • 3
  • 6
  • 23
3
votes
0 answers

How restrict qualifer annotation to specific classes/methods in Spring Boot?

I have a qualifier annotation that I use to autowire a specific bean like this: @Autowired @MyAnnotation private MyClass myClass; @Bean @MyAnnotation public MyClass myClass() { return new MyClassImpl(); } @Retention( RetentionPolicy.RUNTIME…
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
3
votes
1 answer

Bean reference overridden by non-compatible bean instance of type [com.sun.proxy.$Proxy159]

I am a beginner in developing web services and I have a jaxrs web service which has the folllowing config :…
F. Zamfirov
  • 103
  • 1
  • 7
3
votes
2 answers

Service bean not getting autowired in spring boot

I'm creating a Spring boot application with one Controller, Service and Repository class.All these are defined below : MainClass @SpringBootApplication public class MainClass extends SpringBootServletInitializer { @Override protected…
Manisha
  • 775
  • 6
  • 13
  • 30