如何解决如何在 Spring Boot 中将 applications.properties 添加到组件中?
我正在使用 Vaadin 14,我想将这些包含到 Spring Boot 的组件类中。
# Database
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.datasource.url=jdbc:mysql://localhost:3306/test?createDatabaseIfNotExist=true&serverTimezone=CET
spring.datasource.username=myUser
spring.datasource.password=myPassword
我想让它看起来像这样。在这里,我可以将类 FTPConnection
和 @Autowired
包含在 view
中,然后随时更改它。
但是这些是用 @PropertySource("classpath:ftp.properties")
导入的,而 applications.properties
不是。那么我该如何更改例如 spring.security.user.name=myUser
动态?我需要创建一个 Component
类吗?
@Component
@PropertySource("classpath:ftp.properties")
public class FTPConnection {
private Logger logger = LoggerFactory.getLogger(getClass());
@Value("${ftp.connectionPath}")
private String connectionPath; // e.g ftp.example.org/folder/path
@Value("${ftp.password}")
private String password;
@Value("${ftp.username}")
private String username;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。