0

だから私は春のボットアプリを持っています:

@Configuration
@PropertySource("${configuration.file}")
public class Application extends SpringBootServletInitializer implements CommandLineRunner {
...
    public static void main(String[] args) throws IOException {
        SpringApplication app = new SpringApplication(Application.class);
        System.setProperty("configuration.file","file:"+"path to my file");
        app.run(args);
    }
...

Windows configuration.file でアプリを実行すると正しく設定されますが、Tomcat サーバーでこれを実行すると次のようになります。

Could not resolve placeholder 'configuration.file' in string value "${configuration.file}"

問題の原因は何ですか?

4

1 に答える 1

1

これは、定義された @PropertySource アノテーションの問題によるものであることは明らかです。その注釈で定義されるプロパティ ファイルの実際の xyz.properties を定義する必要があります。そこにプレースホルダーを与えることもできます。それを行う理想的な方法は、

@Configuration
 @PropertySource("classpath:/com/${my.placeholder:default/path}/app.properties")
public class AppConfig {
 @Autowired
 Environment env;

 @Bean
 public TestBean testBean() {
     TestBean testBean = new TestBean();
     testBean.setName(env.getProperty("testbean.name"));
     return testBean;
 }

}

ここで注釈のさまざまな例を見てください

于 2015-10-13T07:34:20.297 に答える