yaz*_*ara 11 java spring spring-boot
我有一个简单的主应用程序:
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = "dreamteam.eho")
@Import({EhoConfig.class})
public class MainApp implements CommandLineRunner, ApplicationContextAware {
Run Code Online (Sandbox Code Playgroud)
配置:
@Configuration
@EnableConfigurationProperties({RootProperties.class})
public class EhoConfig {
}
Run Code Online (Sandbox Code Playgroud)
和属性:
@ConfigurationProperties("root")
public class RootProperties {
private String name;
Run Code Online (Sandbox Code Playgroud)
我尝试加载配置:
--spring.config.location=file:///E:/.../eho-bot/props/ --spring.profiles.active=eho
Run Code Online (Sandbox Code Playgroud)
路径是正确的.但是没有加载yml;
application-eho.yml文件:
logging:
file: D:/java/projects/telegram-bots/eho.log
level:
dreamteam.eho: INFO
org.springframework: DEBUG
root:
name: EHO-BOT
Run Code Online (Sandbox Code Playgroud)
应用程序使用args运行,但所有props都为null.记录属性不适用; SOUT:
--spring.config.location=file:///E:.../eho-bot/props/
--spring.profiles.active=eho
--spring.output.ansi.enabled=always
Run Code Online (Sandbox Code Playgroud)
此时你应该使用 spring-boot。
@SpringBootApplication
public class ReTestsApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ReTestsApplication.class);
application.setWebEnvironment(false);
application.setBannerMode(Banner.Mode.OFF);
application.run(args);
}
public void run(String... args) throws Exception {
}
}
Run Code Online (Sandbox Code Playgroud)
使用 webEnvironmet=false 和 BannerMode=off(控制台应用程序)。
| 归档时间: |
|
| 查看次数: |
21960 次 |
| 最近记录: |