我从jar
生成了Spring-Boot
。我想从命令行执行此jar
。我明确地将此jar
复制到了不在我的Eclipse工作区中的文件夹D:\test
中。我还将D:\test
的{{1}}文件放在application.properties
我的Spring-Boot主应用程序包含一个PropertySource批注,该批注引用了从命令行提供的变量:
app.title = Testing
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.axian.oxalys.*")
@PropertySource({"file:${app.home}/application.properties"})
public class App {
@Value("${app.title}")
private static String appTitle;
public static void main(String[] args) {
System.out.println("-------------------------------------------");
System.out.println("------------- app property = "+appTitle);
System.out.println("-------------------------------------------");
}
}
是:
application-context.xml
因此,当我从<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:ldap="http://www.springframework.org/schema/ldap" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<!-- Resources import -->
<jpa:repositories base-package="com.axian.oxalys.*" />
<context:component-scan base-package="com.axian.oxalys.*" />
<context:annotation-config />
<!-- Import deployment configuration file path from JNDI -->
<bean id="configurationPath" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/application.properties</value>
</property>
</bean>
<!-- Load our substitution properties into a Properties object. -->
<bean id="configurationProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<ref bean="configurationPath" />
</property>
</bean>
<!-- Property configurer for pulling property settings from properties -->
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<ref bean="configurationProperties" />
</property>
</bean>
</beans>
执行命令行:D:\test
时,变量appTitle会为空!那怎么了?