你好,我是JAVA Spring Boot的初学者。 我无法从 aplication.yml 获取值或从单例类中的服务(JpaRepository( 获取值
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class AuthProviderService {
@Value("${test.value}")
private String testvalue;
@Autowired
private ProductService productService;
}
Spring 引导以特定方式加载属性。请检查文件名中的拼写错误(application.yaml(
-
14.打包罐子之外的应用程序属性(应用程序属性和 YAML 变体(。
-
15.打包在罐子中的应用程序属性(应用程序属性和 YAML 变体(。
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
此外,请考虑封装您的配置以@ConfigurationProperties