首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >依赖jar中application-context.xml中的Spring属性占位符

依赖jar中application-context.xml中的Spring属性占位符
EN

Stack Overflow用户
提问于 2017-06-07 21:30:38
回答 0查看 1.1K关注 0票数 0

对于我的spring boot应用程序,我使用了基于注释的配置和WebApplicationInitalizer

我的一个依赖项在包含在jar中的xml中提供了一个spring配置。我使用@ImportResource加载上下文xml。这似乎是可行的,只是在这个xml中有属性占位符,例如${poolsize:10}

显然,spring不会自动替换这些占位符(我得到了一个NumberFormatException)。我需要添加一些额外的配置吗?

我们的启动类:

代码语言:javascript
复制
public class Application implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext container) throws ServletException {
        // Create the 'root' Spring application context
        AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();

        // config
        rootContext.register(JmsConfiguration.class);

        // Manage the lifecycle of the root application context
        container.addListener(new ContextLoaderListener(rootContext));
    }

}

和configuration类(我们使用spring-jms):

代码语言:javascript
复制
@Configuration
@EnableJms
@ComponentScan(basePackages = { "..." })
public class JmsConfiguration implements JmsListenerConfigurer {
       // config for jms listener and jaxb, nothing to do with property handling
}

也许我错误地认为使用WebapplicationInitializer就是使用spring boot。也许我们甚至不需要弹力靴?我们使用的唯一与spring boot相关的依赖关系是:

代码语言:javascript
复制
<dependency>
    <!-- Import dependency management from Spring Boot -->
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>1.5.3.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

我们使用的Spring依赖:

代码语言:javascript
复制
org.springframework:spring-context:jar:4.3.8.RELEASE:compile
org.springframework:spring-jms:jar:4.3.8.RELEASE:compile
org.springframework:spring-oxm:jar:4.3.8.RELEASE:compile
org.springframework:spring-context:jar:4.3.8.RELEASE:compile
org.springframework:spring-beans:jar:4.3.8.RELEASE:compile
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44414138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档