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 8018373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:06:54+00:00 2026-06-04T21:06:54+00:00

I have a doubt in using beans generated by another project. To be more

  • 0

I have a doubt in using beans generated by another project. To be more detail :

I have a project A as follows

public A {
public void print()
{
System.out.println("Hello World");
}
}

The config class is as follows

@Configuration
public class AConfig {  
@Bean
public A a()
{
    A bean = new A();
    return A;
}
}

Now I have a new project B which has class as follows

public B {
A a;
public setA()
{
this.a = a;
}
public static void main(String[] args)  
{ 
System.out.println(a.print());
}
}

config class for B as follows

@Configuration
@Import(AConfig.class)
public BConfig
{
@Bean
public B b()
{
B bean = new B();
**b.setA(a());-----------------This is not correct. How can i get Instance of class A NOw????**
}
}

Thanks

  • 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-04T21:06:54+00:00Added an answer on June 4, 2026 at 9:06 pm

    Merge @Configuration classes

    If beans are tightly coupled, just put them in the same class:

    @Configuration
    public class AConfig {  
        @Bean
        public A a() {
            return new A();
        }
    
        @Bean
        public B b() {
            B b = new B();
            b.setA(a());
            return b;
        }
    }
    

    Inject another @Configuration class

    @Configuration class is just a special case of a bean in Spring:

    @Configuration
    public class BConfig {  
    
        @Autowired
        private AConfig aConfig;
    
        @Bean
        public B b() {
            B b = new B();
            b.setA(aConfig.a());
            return b;
        }
    }
    

    Inject dependencies to @Configuration class

    @Configuration
    @Import(AConfig.class)
    public class BConfig {  
    
        @Autowired
        private A a;
    
        @Bean
        public B b() {
            B b = new B();
            b.setA(a);
            return b;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one doubt regarding casting. public void Test(out T a, out T b)
I have doubt using jpa. I defined the datanucleus connection for MYSQL as follows.
I have a doubt in layouts.I have designed one layout using group layout using
I am thinking about using Gears in a project, but I have doubts about
I have a doubt regarding the backlog value in listen system call. From man
I have been learning about TDD (using JUnit) and I have a doubt about
I have this doubt from long time, When ever I write the class using
I have no doubt that for client applications, AsParallel() will bring some out-of-the-box performance
I have a serious doubt on using GWT. GWT claims that the client codes
I m just learning regular expression matching using javascript, and have a doubt regarding

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.