微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring Boot Environment.getProperty返回org.jboss.as.naming.NamingContext

如何解决Spring Boot Environment.getProperty返回org.jboss.as.naming.NamingContext

我有一个具有动态属性的spring boot 2.3.x应用程序,并已使用@PropertySource加载了它们。该应用程序可以使用 @Autowired Environment getProperty()方法获取属性值,并且可以与 Tomcat

正常工作

custom_config.properties

system_abc=1
system_def=1
system_xyz=5

代码

@Component
public class SystemResolver {

    @Autowired
    private Environment env;

    public String getSystemValue(final String sysId) {
         return env.getProperty("system_" + sysId);
    }

我面临的问题是当尝试在JBoss EAP 7.x中运行应用程序时,@ Autowired Environment getProperty()方法返回 org.jboss.as.naming.NamingContext 而不是 > java.lang.String

Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.jboss.as.naming.NamingContext] to type [java.lang.String]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174)
at org.springframework.core.env.AbstractPropertyResolver.convertValueIfNecessary(AbstractPropertyResolver.java:265)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:91)
at org.springframework.core.env.PropertySoutrcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:62)
at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:535)

我尝试从standalone.xml中排除JBoss子模块“命名”,但是它在应用程序启动时引发了问题

分享一些有关如何克服JBoss EAP 7.x行为的信息。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。