我正在尝试注入一个在server.env
.
@Inject
@ConfigProperty(name = "property")
private String serverProperty;
内容 server.env
property=server-env-property
我已经在里面添加了pom.xml
<serverEnv>src/main/liberty/config/server.env</serverEnv>
期间读取liberty-maven-plugin:2.2:package-server
CWWKM2144I: Update server configuration file server.env from /Users/abalaniuc/code/config/src/main/liberty/config/server.env.
但是,当应用程序执行时,我得到了这个错误:
The property property was not found in the configuration.
堆栈跟踪:
[ERROR ] CWMCG5003E: The [BackedAnnotatedField] @Inject @ConfigProperty private com.microprofile.study.config.config.ConfigTestController.serverProperty InjectionPoint dependency was not resolved. Error: java.util.NoSuchElementException: CWMCG0015E: The property property was not found in the configuration.
at com.ibm.ws.microprofile.config.impl.AbstractConfig.getValue(AbstractConfig.java:175)
at [internal classes]
显然我错过了一些东西,但无法弄清楚到底是什么。你能帮我么?
正如以下答案中所建议的,我已从.
属性名称中删除,但仍然得到相同的结果。
Liberty 插件配置:
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>${openliberty.maven.version}</version>
<executions>
<execution>
<id>package-server</id>
<phase>package</phase>
<goals>
<goal>create-server</goal>
<goal>install-apps</goal>
<goal>package-server</goal>
</goals>
<configuration>
<outputDirectory>target/wlp-package</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>${openliberty.version}</version>
<type>zip</type>
</assemblyArtifact>
<configFile>src/main/liberty/config/server.xml</configFile>
<serverEnv>src/main/liberty/config/server.env</serverEnv>
<bootstrapPropertiesFile>src/main/liberty/config/bootstrap.properties</bootstrapPropertiesFile>
<appArchive>${project.build.directory}/${final.name}.war</appArchive>
<packageFile>${project.build.directory}/${final.name}.jar</packageFile>
<include>runnable</include>
<serverName>${final.name}</serverName>
<installAppPackages>project</installAppPackages>
</configuration>
</plugin>
要启动应用程序,我会这样做:
mvn clean package
java -jar target/config.jar