尝试用serviceComb框架跟Spring boot框架结合写了一个测试应用,结果放到云服务器上启动的时候报错,大概错误如下:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'HOSTNAME%%.*' in value "history -a; printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}""
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveNestedPlaceholders(AbstractPropertyResolver.java:227) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:84) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:61) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:527) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.apache.servicecomb.config.ConfigurationSpringInitializer.getProperties(ConfigurationSpringInitializer.java:141) ~[foundation-config-1.0.0.jar:1.0.0]
at org.apache.servicecomb.config.ConfigurationSpringInitializer.getAllProperties(ConfigurationSpringInitializer.java:122) ~[foundation-config-1.0.0.jar:1.0.0]
at org.apache.servicecomb.config.ConfigurationSpringInitializer.setEnvironment(ConfigurationSpringInitializer.java:61) ~[foundation-config-1.0.0.jar:1.0.0]
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:106) ~[spring-context-4.3.16.RELEASE.jar:4.3.16.RELEASE]
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97) ~[spring-context-4.3.16.RELEASE.jar:4.3.16.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409) ~[spring-beans-4.3.16.RELEASE.jar:4.3.16.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1622) ~[spring-beans-4.3.16.RELEASE.jar:4.3.16.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.16.RELEASE.jar:4.3.16.RELEASE]
... 14 common frames omitted
配置里面根本就不需要用到HOSTNAME%%.*,所以这下有点蒙蔽,查看相关源码也没有要读取这个HOSTNAME%%.*,不得已,用env命令看了下云服务器,发现了一个重要的变量:
PROMPT_COMMAND=history -a; printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}
明显的,就是系统的变量读取方法${}跟spring boot那一套冲突了,解决的办法就是去掉这些${},想办法用另一种方式替换。
最后搞定!