dependency « Bean « Spring Q&A

1. inject property value into Spring bean

I have a bunch of Spring beans which are picked up from the classpath via annotations, e.g.

public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
    // Implementation omitted
In the ...

2. How to wire Interdependent beans in Spring?

I want to declare two beans and instantiate them using Spring dependency injection?

<bean id="sessionFactory" class="SessionFactoryImpl">
 <property name="entityInterceptor" ref="entityInterceptor"/>

<bean id="entityInterceptor" class="EntityInterceptorImpl">
 <property name="sessionFactory" ref="sessionFactory"/>
But Spring throws an exception saying "FactoryBean which is ...

3. Programmatically set a specific bean object - Spring DI

In my program I need to programmatically configure an ApplicationContext. Specifically, I have a reference to an instance of MyClass and I want to define it as a new bean called ...

4. spring: a bean that receives a list of Classes

I want to define in my Spring XML context a bean that has a property of the type List of classes: i.e. List<Class<?>> classes How do I send that bean a number ...

5. spring: set property of one bean by reading the property of another bean?

Is it possible to set the property of one bean by reading the property of another bean? For instance, suppose I had:

class A {
   void setList(List list);

class B {

6. Accessing Spring bean *not* by dependency injection

We have some domain objects that are created at runtime - not by Spring. These domain objects need access to some service type beans that are being managed by Spring. ...

7. spring dependency injection in any java bean

I have application that look like below

without spring (prior)

UI-> service --> javabean p.s: my ui call service (not using DI) and i want to remain this way
new service() ...

8. After setting up the bean in the xml, how to you instantiate the object?

Once you have wired up the bean in the xml file, how to you instantiate the object? Is it just like:

Myobject myObject = new MyObject();
And spring under the covers will perform the ...

9. What does "bean X is injected into bean Y" mean in context of Spring framework

Seems,that very basic question.
Anyway can't get the meaning of next definition from Spring tutorials - "bean X is injected into bean Y" . Does it mean composition relation between classes(when one bean ...

10. How to collect and inject all beans of a given type in Spring XML configuration

One of the strongest accents of the Spring framework is the Dependency Injection concept. I understand one of the advices behind that is to separate general high-level mechanism from ...

11. Spring properties (property-placeholder) autowiring

I have in my applicationContext.xml

<context:property-placeholder location="classpath*:*.properties" />

<bean id="clientPreferencesManager" class="" >
    <property name="clientApiUrl" value="${clientapi.url}" />     
Is it possible to do the same by autowire ? ...

12. Injecting Annotated Bean into Regular Bean


<bean id="myBean" class="com.myapp.MyClass">
    <property ref="myService"/>
public class MyService {
This will throw an exception stating that no bean can be found for property "myService", which I understand because it ...

13. conditional beans using spring

I am trying to write a ValidatorFactory which will give me a validator based on its type

public Validator getNewValidator(ValidatorType type){


14. How to turn Spring @Autowired required property to false for test?

I've been using the @Required annotation up to now to ensure DI of my beans in a Spring configured application. To enable the annotation, you need to declare a RequiredAnnotationBeanPostProcessor bean in ...

15. How to programmatically create bean definition with injected properties?

I want to programmatically add a bean definition to an application context, but some properties of that definition are other beans from that context (I know their names). How can I ...

16. Is it possible to define a dependency between two beans in Spring outside of the definition of the two beans?

I use the depends-on attribute in our production system to control the shutdown order of the beans. Thus, Bean1 doesn't have a compile-time dependency on Bean2, but it should ...

17. Spring bean fields injection

Using Spring IoC allows to set bean properties exposed via setters:

public class Bean {
    private String value;
    public void setValue(String value) {

18. Why is my bean null?

I am trying to learn how to use applicationContext. My goal is to swap out a mock data repository for a real one when using my unit tests. I don't want ...

19. Converting Boolean bean creation to boolean using Spring

So, I have something like this in one of my java files:

@Resource(name = "initializationCache")
Boolean initializationCache;
In a config file, I have this:
<bean id="initializationCache" class="java.lang.Boolean">
    <constructor-arg value="${initialization.cache}" />
How would I ...

20. So NOW why is my bean null?

I recently asked this question regarding pulling beans out of an applicationContext. The answer was indeed helpful, but now it seems I have a problem with accessing this bean from ...

21. Spring: how to hide bean from dependency injection?

The situation is that I have two different resource bundles, a general one and a more specific one. They don't share any message keys. General one:

<bean id="messageSourceGlobal" class="">
    <property ...

22. Spring3's @Configuration cannot @Inject component-scanned beans

This is my app.xml :

<context:component-scan base-package="destiny.web" />
And there is a Dao(interface) , and DaoImpl (annotated with @Repository) inside destiny.web package. There is another Spring3's destiny.web.AppConfig class :
public class AppConfig

23. Java spring bean configuration error

in my web application developped with GWT, Hibernate ans Spring, I encounter when setting the jobClass bean in the application-context.xml file. I get this error at runtime :

Error 500 Error creating bean ...

24. Using a property as a qualifier for Dependency Injection in spring

Is it possible to @Autowire a bean by name (ie. use a @Qualifier) but get the name of the bean from a property set by the BeanFactoryPostProcessor. So in short something ...

25. Spring XML from existing beans - how?

I have java beans:

package com.denisk.beans;
public class SomeBean {
    private String someProperty;
    private AnotherBean anotherBean;

public class AnotherBean {
    private ...

26. spring - Unsatisfied dependency expressed through object property

I am receiving the following error when attempting to inject my dao into a unit test class using spring.

SetUp : Spring.Objects.Factory.UnsatisfiedDependencyException : Error creating object with name 'FruitDaoTest' ...

27. Spring - Injecting main bean into property bean

I am trying to configure such a relation in spring:

MyObject myObject = new MyObject();
myObject.setEntity( new Entity(this) );
is it possible? When I am trying such a configuration:
<bean id="myObject" class="MyObject" ...

28. How to use the @Value annotation with a Spring PropertyPlaceholderConfigurer in a Spock test?

It is possible to use the @Value annotation with a Spring PropertyPlaceholderConfigurer?

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
The <util:properties id="appProperties" location="" /> works correct with @Value but i would ...

29. How to inject String property in a spring bean

We inject simple property with configuration as shown below :

<bean id="myService" class="">
    <property name="myProp" value=""/>
How would you do it with annotations?

30. Spring - how to inject a bean into class which is created many times at runtime?

I needed to initialize a bean at the application startup so I did that in applicationContext.xml. But now I need to inject that bean into an object which is created at ...

31. Spring framework - Preloading beans and looping through them without knowing names

Is there a way I can preload all beans from the XML file at once and then loop through them without knowing their bean names? I've seen that it is obviously ...

32. Spring not injecting bean if it is instantiated on definition

I have a session scoped bean defined like so:

<!-- this is where the serviceImpl bean is defined -->
<import resource="classpath:META-INF/*-core-context.xml"/>

<bean id="myBean" class="">
    <property name="service" ref="serviceImpl"/>
Now inside the bean I ...

33. Spring/Camel Garbage Collection with Dependency Injections

I have configured a Spring app (using Camel for integration with an ActiveMQ broker) such that two particular classes, say, Person and Personality, get wired-up and injected with all of their ...

34. Does Spring framework makes possible to inject a collection in annotation-driven fashion?

Is it possible to do the same using annotation-driven injection:

    <bean id="interceptorsList" class="com.mytest.AnyAction">
        <property name="interceptors">

35. Accessing properties from PropertyPlaceholderConfigurer with multiple property files

I am new to spring (3.1) and totally stumped by this problem. I am trying to access a property value "schdestination" using a PropertyPlaceholderConfigurer that is defined in two property files ...

36. Spring set a property using a runtime object?

I have a hard time figuring out how to set a property with the help of spring annotations. I have an abstract base class.

abstract class AbstractTest{
 private static Session session;

 public ...

37. Can output of a method be used to autowire another bean?

I have a following class

public class Customer {
    private String firstName;
    private String lastName;
    public void setFirstName(String fName) {

38. Conditional injection of bean

I want to have inject a bean based on a String parameter passed from client.

public interface Report {

public class ExcelReport extends Report {
    //implementation ...

39. Can't get Spring to inject my dependencies - Spring Newbie

I've been trying for 2 days now to get Spring to inject an @Autowired dependency into my application without avail. What am I doing wrong? I created a bean called TimeService. It's ...

40. Spring Bean (Mis-)Configuration

I'm new to Spring and am trying to accomplish two objectives:

  1. I want to keep my application's config data (server IPs, credentials, etc.) in a deployment-specific properties file (``)
  2. I want to use ...

41. Spring Qualifier and property placeholder

Does anyone know if I should be able to use property placeholder as an expression in a Qualifier? I can't seem to get this working. I am using spring 3.0.4.

public class MyController ...

42. Dependency Injection btw Bean in a List

Dependency Injection btw Bean in a List I did some google, but I couldnt find any case similar like my case. So I post my case here. I was trying to ...

43. Multiple "inheritance" (initialzation) of dependencies for bean definitions.

Multiple "inheritance" (initialzation) of dependencies for bean definitions. In my project I need something like multiple inheritance (better to say inheritance of dependencies) for bean definitions. Of course, it is clear ...

44. How to inject dependency for a variable where value is coming from a property file?

How to inject dependency for a variable where value is coming from a property file? Hi, I have to create a spring Bean like, @Service public class TestService implements ITestService { ...

45. Stopping Spring calling my beans that implement Map during dependency injection?

Stopping Spring calling my beans that implement Map during dependency injection? Hi, If I have beans that implement Map, and use them in dependency injection, Spring calls methods on the bean ...

46. InitializingBean / Abstract bean dependency broken

InitializingBean / Abstract bean dependency broken I have an abstract class: Code: public abstract class AbstractBrowseManagerMultiactionController extends MultiActionController implements InitializingBean { private BrowseManager browseManager; public BrowseManager getBrowseManager() { return browseManager; } ...

47. Synthetic Properties With Dependency Injection

Synthetic Properties With Dependency Injection In the interests of reducing lines of code, i'd like to explore the use of synthetic properties. That is, rather than having to create a member ...

48. interceptor with dependency on another bean

interceptor with dependency on another bean Hello I'm trying to implement cache system using http filters and aop. I'v got an interceptor that clears cache buffers when some methods are invoked ...

49. bean dependency issue

bean dependency issue Hello All I have two applications running on JBoss server packaged as ear and war. Some classes in war depends on couple of singletons, facade around EJBs, in ...

50. injecting dependencies on beans which are not created by Spring

Hi, Is there any way to do DI with Spring, and not the instantiation? I have a non-singleton (prototype) bean created by Spring, with dependency on some other non-serializable beans (such ...

51. Wrong dependency resolving/getting injected uninitialized beans

Wrong dependency resolving/getting injected uninitialized beans Sometimes I have some problems with the order of the initializing of beans which end in strange "null errors" or even NPEs. The reasons seems ...

52. Dependency injection of Aspect backing bean issue

Dependency injection of Aspect backing bean issue Before I get into the issue, this is what I am trying to do. I have Spring 2 wired to Hibernate 3 and am ...

53. How do you set a dependency on a property that is set programatically.

How do you set a dependency on a property that is set programatically. Hi, I have been trying to find the answer to that question but haven't found one yet. My ...

54. Inject Dependency on Outer Bean

Inject Dependency on Outer Bean Is it possible to inject a reference to a containing bean into an inner bean for prototype beans? Something like: ...

55. init bean (from spring 2.0.2 spring-framework-2.5-with-dependencies)

Jan 31st, 2008, 04:03 PM #1 pingping View Profile View Forum Posts Private Message Junior Member Join Date Jan 2008 Posts 1 init bean (from spring 2.0.2 spring-framework-2.5-with-dependencies) I am upgrading ...

56. Problem with bean dependencies configuration

Problem with bean dependencies configuration Hi! I have implemented an Hibernate interceptor to perform custom actions when saving an entity. I have configured it like this in Spring applicationContext.xml Code:

57. Dependency inject abstract class property

Hi Can someone help me with this. I have a base class that contains some generic functionality. This class is abstract. I then have a set of subclasses. The abstract class ...

58. Initializing Beans in a dependency

I have a web application which uses a number of service jars. The service jars are standalone components which have there own application context bean definitions. Is there a way to ...

59. Load only dependencies of requested bean?

Hi all, Imagine I have a context file with a lot of controller beans. I want to run a single controller test. When I run this test I only want the ...

60. bean dependency question

bean dependency question I have a bean which exports a service using HttpInvoker/https. When my web-app starts up, I want to have this bean announce itself to other entities by posting ...

61. How to dependency inject properties that have Java objects associated to them?

Hi, I have a class called Person, which has Name (String), Address (String), dateOfBirth (java.util.Calendar) properties. I want to set values for these members through dependency injection. My query - is ...

62. Adding dependency injection to JAX-B bean?

63. Bean dependency spanning bundles?

Bean dependency spanning bundles? Hi! my application is composed of several DM-powered bundles and I need to split some funcionality in different bundles. E.g., I have a bundle "server.core" that is ...

64. Bean dependencies across context files fail

Bean dependencies across context files fail This might be a limitation of spring contexts, or (more likely) I'm missing some configuration. Scenario: - 2 apps (one is main app, one is ...

65. Define enum as Spring Bean and dependency inject it into another Spring Bean

You missed the forum - the question is not related to AOP at all; Your config declares a new instance of class 'org.poc.MyEnum' that should be instantiated using no-args constructor. It's ...

66. @Bean dependency in @Autowired within same @Configuration not working

@Bean dependency in @Autowired within same @Configuration not working Hi, I've run into this issue a few times now and have found ways to work around it but I'm wondering if ...

67. dependency injection and beans

Hello, Ive got a newbie question. If you develope a bigger project by using spring - do you then every object create by using beans?! I mean, do you avoid to ...