cod*_*ent 5 java maven-3 maven maven-resources-plugin maven-archetype
由于其中一种资源中存在冒号(':'),因此我无法创建Maven原型。我有一个包含该符号的Spring XML:
<property name="maxSize" value="${ws.client.pool.maxSize:5}"/>
Run Code Online (Sandbox Code Playgroud)
启动原型时,出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate
(default-cli) on project standalone-pom:
org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates:
Encountered ":5}\"/>\n\t</bean>\n\t\n\t<bean id=\"fooServiceClient\" class=\"org.springframework.aop.framework.ProxyFactoryBean\">\n\t <property name=\"targetSource\" ref=\"fooServiceClientPoolTargetSource\"/>\n\t</bean>\n\n</beans>\n"
at line 15, column 69 of archetype-resources/src/main/resources/spring/library.ws-client.xml
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
[ERROR] "(" ...
[ERROR] -> [Help 1]
[ERROR]
Run Code Online (Sandbox Code Playgroud)
我尝试在原型的pom中配置转义字符:
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.0</version>
</plugin>
<!-- Resources configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<escapeString>\</escapeString>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Run Code Online (Sandbox Code Playgroud)
但是它仍然不起作用。在这种情况下:
<property name="maxSize" value="${ws.client.pool.maxSize\:5}"/>
Run Code Online (Sandbox Code Playgroud)
错误如下:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate
(default-cli) on project standalone-pom: org.apache.maven.archetype.exception.ArchetypeGenerationFailure:
Error merging velocity templates:
Encountered "\\" at line 15, column 69 of archetype-resources/src/main/resources/spring/library.ws-client.xml
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
[ERROR] "(" ...
[ERROR] -> [Help 1]
[ERROR]
Run Code Online (Sandbox Code Playgroud)
关于如何逃脱冒号的任何想法?
对于可选属性,以下Spring注入代码发生了相同的错误:
@Value("${hostname:}")
private String hostName;
Run Code Online (Sandbox Code Playgroud)
解决方案:
#set( $dollar = '$' )
@Value("${dollar}{hostname:}")
private String hostName;
Run Code Online (Sandbox Code Playgroud)
关键步骤是将对$常量的引用包装在{curly braces}中
我根据速度变量($maxSize)制定了一个解决方案:
#set( $maxSize = '${ws.client.pool.maxSize:5}' )
<bean id="fooServiceClientPoolTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">
<property name="targetBeanName" value="fooServiceClientTarget"/>
<property name="maxSize" value="$maxSize"/>
Run Code Online (Sandbox Code Playgroud)