我使用exec-maven-plugin执行java应用程序在我的项目中执行代码生成:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>
如果我在命令行“mvn exec:java”中执行,这可以正常工作,但是现在我想将这个代码生成附加到maven阶段“generate-resources”,所以我把pom更改为:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>codegeneration</id>
<phase>generate-resources</phase>
<goals><goal>java</goal></goals>
</execution>
</executions>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>
但是当我执行“mvn exec:java”时突然出现了错误:
[09:52:03.926] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [WARN ] [AbstractApplicationContext.java:550] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'codeGeneratorApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cnp.application.acronym' in value "${cnp.application.acronym}"
[09:52:03.940] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [INFO ] [DirectJDKLog.java:179] - Stopping service Tomcat
[09:52:03.982] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [INFO ] [AutoConfigurationReportLoggingInitializer.java:101] -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
[09:52:03.987] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [ERROR] [SpringApplication.java:815] - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'codeGeneratorApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cnp.application.acronym' in value "${cnp.application.acronym}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.codegenerator.CodeGeneratorApplication.main(CodeGeneratorApplication.java:26)
有人可以帮我解决错误吗?谢谢!
答案 0 :(得分:1)
您的“配置”元素必须位于“执行”元素之内。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>codegeneration</id>
<phase>generate-resources</phase>
<goals><goal>java</goal></goals>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>