别慌!它是/must be在工作...
从简单开始:
quickstart-maven, dependencies: web (only)个
只是一个演示(否/空application.properties
,according to 102 we can refer to any 100/custom "property";):
package com.example.demo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoConfigApplication {
public static void main(String[] args) {
SpringApplication.run(DemoConfigApplication.class, args);
}
@Bean
InitializingBean test(
@Value("${foo.bar:undefined}") String fooBar,
@Value("${foo.baz:undefined}") String fooBaz
) {
return () -> {
System.err.format("foo.bar: %s%n", fooBar);
System.err.format("foo.baz: %s%n", fooBaz);
};
}
}
建房
./mvnw clean test
打印:
...
foo.bar: undefined
foo.baz: undefined
...
要通过(springot-)maven-plugin设置这些插件,我们可以:
(转到)
通过"命令行参数"
(用空白,用我的胜利+gitbash:
GNU bash, version 5.2.12(1)-release (x86_64-pc-msys)
)
Syntax:
./mvnw spring-boot:run -Dspring-boot.run.arguments="--foo.bar='Foo Bar' --foo.baz='Foo Baz'"
(输出):
...
2023-03-15T13:45:52.849+01:00 INFO 4196 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1106 ms
foo.bar: Foo Bar
foo.baz: Foo Baz
...
通过"系统属性"(Same Git Bash):
Syntax:
./mvnw spring-boot:run -Dspring-boot.run.jvmArguments="-Dfoo.bar='Foo Bar' -Dfoo.baz='Foo Baz'"
使(例如)在……工作
Cmd.exe
(版本10.0.19045.2673),引用与gitbash相同:
.\mvnw.cmd spring-boot:run -Dspring-boot.run.arguments="--foo.bar='Foo Bar' --foo.baz='Foo Baz'"
Powershell
(v7.3.3)
更复杂,由于/有ref:
.\mvnw.cmd spring-boot:run '-Dspring-boot.run.arguments="--foo.bar=""Foo Bar"" --foo.baz=""Foo Baz"""'
...