Spring boot – bean

Spring beans are Java POJO classes created, wired, configured, and managed by the Spring container from start to finish. The Spring container uses DI to manage the components that make up an application. 

The Spring container gets its instructions on what objects to instantiate, configure, and assemble by reading the configuration metadata(Configuration classes) provided. The configuration metadata can be represented either by XML, Java annotations, or Java code. The Spring IoC container makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application.

Add Java configuration class

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

import com.lovemesomecoding.service.UserService;
import com.lovemesomecoding.service.UserServiceImpl;

@Configuration
public class BeanConfig {

    @Bean
    public UserService userService() {
        UserService userService = new UserServiceImpl();
        return userService;
    }

}

Source code on Github




Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Leave a Reply

Your email address will not be published.