0

For my spring boot application I use annotation based configuration and a WebApplicationInitalizer.

One of my dependencies provides a spring configuration in an xml, included in the jar. I use @ImportResource to load the context xml. This seems to work, except for the fact that inside this xml, there are property placeholders, for example ${poolsize:10}

Apparently, spring does not automatically replace these placeholders (I get a NumberFormatException). Is there some extra configuration I need to add?

Our startup class:

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));
    }

}

And the configuration class (we use spring-jms):

@Configuration
@EnableJms
@ComponentScan(basePackages = { "..." })
public class JmsConfiguration implements JmsListenerConfigurer {
       // config for jms listener and jaxb, nothing to do with property handling
}

Perhaps I'm mistaken in thinking that using a WebapplicationInitializer is how to use spring boot. Perhaps we don't even need spring boot? The only spring boot related dependency we use is:

<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 dependencies we use:

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
mrMario
  • 1
  • 4
  • That should work out-of-the-box. If it doesn't, you probably already added too much. You are using Spring Boot then why would you need a `WebApplicationInitializer`? Looks like you are trying to use Spring Boot but not in the intended way. – M. Deinum Jun 07 '17 at 13:35
  • Hey Marten, thanks for the response. I'm actually working on one of your old applications at the moment (WSB) :) This question is about a new application which we want to deploy on jboss EAP 6. I will update the question with some more code. – mrMario Jun 08 '17 at 08:17

1 Answers1

0

I figured it out thanks @M. Deinum

We don't need spring boot to use the WebApplicationInitializer, but (at least without spring boot) we have to declare our own PropertySourcesPlaceholderConfigurer:

@Configuration
@ImportResource(locations = {"classpath*:/library-context.xml"})
public class MyConfiguration {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

}

NB. This works out of the box in spring boot thanks to @EnableAutoConfiguration and @PropertyPlaceholderAutoConfiguration which contains the exact same PropertySourcesPlaceholderConfigurer bean

mrMario
  • 1
  • 4