0
votes

I have two projects - one is based on the "get started" example, second is from the spring-boot-samples. I build both with Maven and run both from Eclipse. The "spring-boot-samples" project loads application.properties and displays Velocity templates named by the Controller. The "get started" does not.

Same file structure for application.properties (src/main/resources/application.properties) and templates (src/main/resources/templates/**), both with src/main/resources set to "Use as Source Folder" in Eclipse. Same workspace, same JRE.

I compared the .classpath and pom.xml, but found nothing suspicious. Obviously there's a difference, but where do I have to look?

PS: I can load application.properties via @PropertySources, but

  • that should not be neccessary (see comments there)
  • is not necessary in the "spring-boot-samples" project
  • does not help concerning the Velocity templates

Thanks!

2

2 Answers

0
votes

To fetch values from application.properties in spring boot, we need to specify some annotation.

  • application.properties must be in the path src/main/resources

  • class must contain @RestController annotation

    @Value("${name}") private String name;

0
votes

Ah, one important difference:

@RestController delivers the response directly, meaning: Instead of resolving the template's name the String is passed to the browser. The reason should be @ResponseBody:

Annotation that indicates a method return value should be bound to the web response body.

Using @Controller instead solves the Velocity problem.

EDIT:

To close this thread: I will continue using @PropertySources to get application.properties, but it does not work without it. Just having application.properties in your classpath is not sufficient.