Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Spring5 beans using annotation configuration

NotificationsYou must be signed in to change notification settings

Sudarshan-Gowda/Spring5-BeanUsingAnnotationConfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This repo will demonstrate how to create spring beans using annotations (via java configuration) for any standalone application.

There are two ways we can create the bean

•Using component annotations•Using @Bean annotations

1.Using component scanning

1.1 We can use any one of following four annotations as appropriate.

  @Component  @Repository  @Service  @Controller

In this repo example we used@Service annotation to get bean

@Service public class TechnologyServiceImpl implements ITechnologyService

1.2Include bean packages in@ComponentScan annotation

@Configuration @ComponentScan(basePackages = "com.star.sud.using.ComponentScanAnnotation.service") public class ApplicationConfig

2.Using @Bean annotations

1.1Create Java bean classes without any annotation.

public class TechnologyServiceImpl implements ITechnologyService

1.2Use @Bean annotation methods in configuration class

@Configuration public class ApplicationConfig { @Bean public ITechnologyService technologyService() { return new TechnologyServiceImpl(); } }

Result of this Application:

TechnologyDetails [techId=1, techName=Java, techDescription=Welcome to Java Learning!]

About

Spring5 beans using annotation configuration

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp