由于其中一个资源中存在冒号(':'),因此无法创建Maven原型。我有一个包含该符号的Spring XML:
<property name="maxSize" value="${ws.client.pool.maxSize:5}"/>
启动原型时出现此错误:
[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]
我尝试在原型的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>
然而它仍然无法运作。在这种情况下:
<property name="maxSize" value="${ws.client.pool.maxSize\:5}"/>
错误如下:
[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]
关于如何逃脱结肠的任何想法?
答案 0 :(得分:4)
对于可选属性,使用以下Spring注入代码时出现相同的错误:
@Value("${hostname:}")
private String hostName;
解决方案:
#set( $dollar = '$' )
@Value("${dollar}{hostname:}")
private String hostName;
关键步骤是在{花括号}
中包含对$ constant的引用答案 1 :(得分:2)
我制定了一个基于Velocity变量($ maxSize)的解决方案:
201
Example
{
"self": "http://www.example.com/jira/rest/api/2/issue/10010/comment/10000",
"id": "10000",
"author": {
"self": "http://www.example.com/jira/rest/api/2/user?username=fred",
"name": "fred",
"displayName": "Fred F. User",
"active": false
},
"body": "Lorem ipsum dolor sit amet...",
"updateAuthor": {
"self": "http://www.example.com/jira/rest/api/2/user?username=fred",
"name": "fred",
"displayName": "Fred F. User",
"active": false
},
"created": "2015-06-23T08:28:32.838+0000",
"updated": "2015-06-23T08:28:32.838+0000",
"visibility": {
"type": "role",
"value": "Administrators"
}
}
Returned if add was successful
400
Returned if the input is invalid (e.g. missing required fields, invalid values, and so forth).
答案 2 :(得分:0)
我在使用 Spring Boot 和 Java 时也遇到了问题。
@Value("${number:0}")
Long number;
Velocity 现在有一种方法可以关闭对带有 #[[
和 ]]#
符号序列的一段代码的解析。它们之间的任何代码都不会被解析,但仍会包含在输出中。
/*
#[[
*/
@Value("${number:0}")
Long number;
/*
]]#
*/
符号应从第一列开始。符号周围需要 Java 注释,以便 Java 代码仍然可以编译。