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

  • SEARCH
  • Home
  • 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 952503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:54:13+00:00 2026-05-15T23:54:13+00:00

There is a @Bean annotation in Spring 3.0. It allows to define a Spring

  • 0

There is a @Bean annotation in Spring 3.0. It allows to define a Spring bean directly in a Java code. While browsing Spring reference I found two different ways of using this annotation – inside class annotated with @Configuration and inside class which doesn’t have this annotation.

This section contains following piece of code:

@Component
public class FactoryMethodComponent {

   @Bean @Qualifier("public")
   public TestBean publicInstance() {
      return new TestBean("publicInstance");
   }

   // omitted irrelevant method
}

And here we could see a very similar piece of code, but now @Configuration is in the place:

@Configuration
public class AppConfig {
   @Bean
   public MyService myService() {
      return new MyServiceImpl();
   }
}

Former section of reference contains following explaination:

The @Bean methods in a Spring component are processed differently than their counterparts inside a Spring @Configuration class. The difference is that @Component classes are not enhanced with CGLIB to intercept the invocation of methods and fields. CGLIB proxying is the means by which invoking methods or fields within @Configuration classes @Bean methods create bean metadata references to collaborating objects. Methods are not invoked with normal Java semantics. In contrast, calling a method or field within a @Component classes @Bean method has standard Java semantics.

But CGLIB is a kind of internal stuff which application developer shouldn’t be aware of (in a ideal world, of course). As I understand in both cases Spring invokes method annotated with @Bean to create Spring bean, in both cases these instances are injected to collaborators.

So my question is what is the difference for me as an application developer between this two cases?

  • 1 1 Answer
  • 1 View
  • 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-05-15T23:54:14+00:00Added an answer on May 15, 2026 at 11:54 pm

    The difference is that with @Configuration you can call one @Bean method from another and get a fully initialized instance, as follows:

    public class Foo {
        @Value("Hello, world!")
        public String value;
    }
    
    @Configuration
    public class Config {
        @Bean
        public Foo createFoo() {
            Foo foo = new Foo();
            System.out.println(foo.value); // Prints null - foo not initialized yet
            return foo;
        }
    
        @Bean
        public Bar createBar() {
            Foo foo = createFoo();
            System.out.println(foo.value); // Prints Hello, world! - foo have been initialized by the interceptor
            return new Bar(foo);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I have a Spring 2.5/Java/Tomcat application. There is the following bean, which is
Is there any way to obtain Object array of Java Bean fields? I have
There are more than two common fields (id ,created_by,modified_date) in DB in different tables.
I would like to use @Repository spring annotation to avoid adding bean in context.xml.
There is a property of type Resource in my Spring 3 bean that should
I use spring roo to build project and it's annotation driven, and there is
I am using java annotation based configuration for initializing ehcache based caching, with Spring
Is there any way can declare a bean in just like JSP UseBean in
Is there any way to get direct URL to a JSF bean action method?
Is there a way to execute a JSF managed bean action when a page

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.