L-Jones9 L-Jones9 - 9 months ago 157
Java Question

Tomcat Not reading Spring-Boot Application Properties

I'm fairly new to spring/java and have been checking out spring-boot for a project I have at work. I've been following guides and finally have a (semi) working web app MVC + JPA for data access. Everything works when I deploy the app via the Jar method :

java -jar build/libs/client.jar

However, our application is eventually going to be deployed to Tomcat (v7.0.40) so I need to create a war file from the project. I've followed the converting jars to war's guide on the spring.io site and have run into a problem. It appears that it is not loading up the application.properties file. Here are the important code snippets:


public class GreetingController {
private String username;

public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
model.addAttribute("username", username);
return "greeting";


public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);


public class HelloWebXml extends SpringBootServletInitializer {

protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);



for completeness, here is the build.gradle:

buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
dependencies {

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
baseName = 'client'
version = '0.1.0'

repositories {
maven { url "http://repo.spring.io/libs-snapshot" }

dependencies {

task wrapper(type: Wrapper) {
gradleVersion = '1.8'

I build the application:

gradle clean build

Drop the war in tomcat, and then tail out the logs and see the following:

SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating the bean
with name 'greetingController': Injection of autowired dependencies failed; nested exception
is java.lang.IllegalArgumentException: Could not resolve placeholder 'app.username' in string
value "${app.username}"

As I said, it works when I run it via a jar, but does not work when I deploy it to Tomcat. I also looked inside
and I see the
file. So I think that it should be on the classpath. My question is, why isn't tomcat loading it? I've tried searching all over and no one else seems to be having this problem so I'm not sure if its just something I have incorrectly configured, or what.

Thanks in advance.

Answer Source

follow this guys advice: http://blog.codeleak.pl/2013/11/how-to-propertysource-annotations-in.html


@PropertySources(value = {@PropertySource("classpath:application.properties")})

then boom sauce for the win.