i actually created a bean in spring context when i get that bean there is an error msg NoSuchBeansDefinationException

0 votes
package com.learningSpring.learningSpring;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HelloWorldConfiguration {
    // Spring Framework

    @Bean
    public String name(){
            // this method will create a bean in the Spring Container
                return "Iqra";
            }

    @Bean
    public int age(){
        // this method will create a bean in the Spring Container
        return 11;
    }


}






Spring Context




package com.learningSpring.learningSpring;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class HelloWorldJava02 {

    public static void main(String[] args) {
        //Lunch a Spring context

        var context=new AnnotationConfigApplicationContext(HelloWorldJava02.class);


        //Configure the things that we want to manage Spring Framework @Configuration
        // How to get Bean from the Spring Context is
        System.out.println(context.getBean("name"));// name is the method name
        System.out.println(context.getBean("age"));


    }
}



Feb 21, 2023 in Java by anonymous

edited 5 days ago 13 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP