728x90
구현방법
1. 의존성 추가
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example.study1</groupId>
<artifactId>cheolju-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
2. @Configuration 파일 작성
@Bean
public Man holoMan(){
return Man.builder()
.name("cheolju")
.age(5)
.build();
}
3. src/main/resource/META-INF spring.factories 파일생성
4. spring.factories 안에 자동 설정 파일 추가
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
study1.HoloManConfiguration
5. mvn install -> local project 내에서 사용 가능
6. 다른 local project 에서 dependency 설정
<dependency>
<groupId>org.example.study1</groupId>
<artifactId>cheolju-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
* 다른 local project에서 같은 이름으로 bean을 등록하는 경우 Componemt-scan으로 등록된 bean이 우선이라 덮어 쓰여짐
> @ConditionalOnMissingBean 를 사용하여 덮어쓰기 방지
* 빈을 재정의 하기 싫은 경우
> Properties Class 생성 후
@Configuration
@EnableConfigurationProperties(ManProperties.class) //추가
public class ManConfiguration {
@Bean
@ConditionalOnMissingBean
public Man Man(ManProperties properties){
return Man.builder()
.name(properties.getName())
.age(properties.getAge())
.build();
}
}
728x90
'Spring Boot' 카테고리의 다른 글
spring boot 내장 웹 서버 변경 (0) | 2022.01.31 |
---|---|
Spring boot 내장 Servlet Container (0) | 2022.01.29 |
@SpringBootApplication (0) | 2022.01.29 |
Spring boot 원리 (0) | 2022.01.01 |
Spring Boot 기초 -1 (0) | 2022.01.01 |
댓글