내 속성 파일에서 속성을로드하는 데 어려움이 있습니다. 아래 나열된 구성 클래스에 속성을로드하려고합니다. 내가 파일 (application.properties) 또는 "@PropertySource의 이름을 변경하는 경우속성 및 env 항상 null
package dk.fitfit.budget.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
@Configuration
@PropertySource("classpath:application.properties")
public class ApplicationConfig {
private static final Logger logger = LoggerFactory.getLogger(ApplicationConfig.class);
@Autowired
private Environment env;
@Value("${snot:test}")
private String snot;
public ApplicationConfig() {
logger.info("Application config loaded!"); // Displays as expected
logger.info("snot: {}", snot); // snot: null
logger.info("env: {}", env); // env: null
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
는 ("클래스 경로 : application.properties을 ")"나는 파일이 존재하지에 대해 오류가 발생합니다. 그래서 분명히로드되고 있습니다 (어쨌든 확장 될 수 있습니다).
변수 snot에 "test"라는 기본 문자열이 삽입 될 것으로 예상되었습니다. 그러나 그것조차도 끝나지 않습니다. 나는 환경을 autowire 수 없습니다 ... 관계가 있는지 확실하지 않습니다.
내 application.properties의 내용은 다음과 같습니다.
snot=snog
내 application.properties 파일은 src/main/resources /에 있습니다.
누구나 내가 뭘 잘못하고 있는지에 대한 단서가 있습니까?
축하해, 마지막 투표가 있습니다. 다른 시간에 투표 할 수 없습니다. –