我的SpringBoot 2.0.3 Java 8程序在Eclipse Photon(使用Maven)上运行良好,但是,当我将其构建到jar文件中并安装在AWS Linux上并在其中运行时,我得到:
2019-06-10 10:07:14.395 WARN 18316 --- [ main]s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ccWrapperApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'tmp.dir' in value "${tmp.dir}"
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ccWrapperApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'tmp.dir' in value "${tmp.dir}"
因此,当在Linux上运行时,spring似乎找不到application.properties vars。为什么不呢?
tmp.dir在src / main / resources / application.properties中定义为:
tmp.dir=tmp
和ccWrapperApplication.java具有:
@SpringBootApplication
// SpringBoot likes to use a database, we don't need one, so we exclude the default dB.
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class CcWrapperApplication implements CommandLineRunner {
@Value("${tmp.dir}")
public String tmpDir;
public static void main(String[] args) {
logger.info("running CcWrapperApplication on " + System.getProperty("os.name"))
SpringApplication.run(CcWrapperApplication.class, args);
}
@Override
public void run(String... args) {
...
}
public String getTmpDir() {
return tmpDir;
}
public void setTmpDir(String tmpDir) {
this.tmpDir = tmpDir;
}
}
我使用eclipse构建了应用程序jar: 导出->可运行的JAR文件
在Linux上安装jar,将jar添加到CLASSPATH(以及所有的SpringBoot jar)中,并使用以下命令从shell脚本中运行:
java com.clarivate.singulatiry.chemworkbench.chemcurator.chemcurator_wrapper.CcWrapperApplication $inputDir $outputDir 2>&1 >>$logfile | tee -a $logfile >>$errorfile
任何帮助表示赞赏。