Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:56:22+00:00 2026-06-04T07:56:22+00:00

I am using Spring @Configuration annotation to configure my application. Currently, I have a

  • 0

I am using Spring @Configuration annotation to configure my application.

Currently, I have a single @Configuration class where all my beans are declared. As the number of beans is growing (more than 30), I want to split it in many classes.

Some beans are using common classes (mainly utility classes) :

Foo.class is an utility class
Bar.class and Baz.class both use Foo.class

I want to have all Foo, Bar and Baz in three distinct @Configuration classes (respectively Conf1, Conf2 and Conf3)

The problem is that I don’t have access to an instance of Conf1 from Conf2 and Conf3 :

Conf1.class

@Configuration 
public class Conf1 {
    @Bean
    public Foo foo() {
        return new Foo();
    }
}

Conf2.class

@Configuration 
public class Conf2 {
    @Bean
    public Bar bar() {
        Bar bar = new Bar();
        bar.setFoo(conf1.foo()); // Not possible !
        return bar;
    }
}

Conf3.class

@Configuration 
public class Conf3 {
    @Bean
    public Baz baz() {
        Baz baz = new Baz();
        baz.setFoo(conf1.foo()); // Not possible !
        return baz;
    }
}

Any idea on how can I solve this issue ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:56:22+00:00Added an answer on June 4, 2026 at 7:56 am

    You should be able to autowire them:

    @Configuration 
    public class Conf2 {
        @Autowired
        Conf1 conf1;
        ...
    }
    

    Alternatively, you can autowire beans rather than configurations:

    @Configuration 
    public class Conf2 {
        @Autowired
        Foo foo;
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Spring MVC with annotation configuration. I have a controller class for
Hello I have strange problem. I configured spring + hibernate. I`m using annotation configuration
I have been using the new feature of Spring 3.1.1 the java based configuration.
I'm using Spring and Hibernate with annotation-driven transactions. When running my application I've received
I am using jsf and spring together in web application. I have configured datasource
I have implemented my GWT application using Spring + GWTP. I want to access
I using annotation configuration for spring context like <context:annotation-config/> <context:component-scan base-package=example/> But project is
i have written a small webapp using spring-security and spring-mvc with an annotation based
I am using java annotation based configuration for initializing ehcache based caching, with Spring
I have an application using Tomcat/Spring 3/JPA/Hibernate but my merges do not commit to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.