Reputation: 136
I'm trying to get some properties from the command line when I start my app. I really try a lot of solution but nothings is working. I'll only use @Value as a last solution
java -jar myjar.jar --test.property=something
Here's some classes
Main class
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplicationBuilder builder = new SpringApplicationBuilder(TestApplication.class);
builder.run(args);
}
}
Config class
@Configuration
@EnableConfigurationProperties(StringProperties.class)
public class StringConfiguration {
@Autowired
private StringProperties stringProperties;
@Bean(name = "customBeanName")
public List<String> properties() {
List<String> properties = new ArrayList<>();
properties.add(stringProperties.getString());
return properties;
}
}
Properties class
@Component
@ConfigurationProperties("test")
public class StringProperties {
private String property;
public String getString() {
return property;
}
}
Upvotes: 0
Views: 738
Reputation: 1061
Ops.....I have tested your code.It is setProperty that missed in StringProperties.
public void setProperty(String property) {
this.property = property;
}
Upvotes: 4