-1
@ConfigurationProperties를 사용하여 속성 파일에서 속성을 바인딩하려고합니다. 하지만 그 값을 인쇄하려고 할 때 실제로 null 또는 Java 데이터 형식의 기본값을 갖는. 아래의 모든 Java & 등록 정보 파일은 동일한 패키지에 있습니다.@ConfigurationProperties는 값을 바인딩하지 않습니다. 데이터 형식에 null 또는 기본값 가져 오기
@SpringBootApplication
@ComponentScan
@EnableConfigurationProperties
public class SimpleMain {
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext ctx = SpringApplication.run(BeanLoader.class, args);
PropertyLoader pl = ctx.getBean(PropertyLoader.class);
System.out.println(pl.getName());
}
}
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("test")
public class PropertyLoader {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class BeanLoader {
@Bean
public PropertyLoader getPropertyLoader(){
return new PropertyLoader();
}
}
application.properties
test.name=karthik
로 교체해야하는 이유 새'AnnotationConfigApplicationContext'를 만들고 그에서 콩을 얻기 위해 노력하고있다 : 여기
코드인가? 왜 두 개의 'PropertyLoader' 빈을 정의하려고합니까? –'@ Component'를 사용하지 마십시오. – chrylis
필자는 autowire 할 수 있지만 AnnotationConfigApplicationContext는 빈을로드 할 때 문제가되지 않아야한다. – karthik