1

Application.properties doesn't get pick up. Very small program not sure what's wrong, I've google and did research.

But when I use this code in FirstController.java it does work....

return new ModelAndView("/WEB-INF/jsp/welcome.jsp","dateAndTime",dateAndTime);

FirstController.java

package com.vpp.fleetman.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@Controller
public class FirstController {

  @RequestMapping("/home.html")
    public ModelAndView firstPage(){
      Date dateAndTime = new Date();
     
     //This work, I just want to remove the hard coded and use application.properties
     // return new ModelAndView("/WEB-INF/jsp/welcome.jsp","dateAndTime",dateAndTime);
    
    //Let's use a view resolver for the views
    return new ModelAndView("welcome","dateAndTime",dateAndTime);
  }
}

webapp/WEB-INF/jsp/welcome.jsp

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<h1>Welcome from Intelij ..... Time is: ${dateAndTime} </h1>

<c:forEach var="i" begin="1" end="5">
    <p>${i}</p>
</c:forEach>

application.properties the default one that is set with the facet

sping.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.virtualpairprogrammers</groupId>
    <artifactId>fleetman</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>fleetman</name>
    <description>VPP Fleet Management Application</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

I get this error when I http://localhost:8080/home.html

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Apr 27 13:57:24 EDT 2021
There was an unexpected error (type=Not Found, status=404).
/welcome.jsp

As soon I use the reference to application.properties it doesn't work... vs when I keep the hard coded ref ?? any guidance would be appreciated.

J Asgarov
  • 2,526
  • 1
  • 8
  • 18
Mike
  • 19
  • 3
  • [here](https://stackoverflow.com/questions/33022827/spring-boot-app-not-picking-up-application-properties) and [here](https://stackoverflow.com/questions/43818248/spring-boot-not-recognizing-application-properties-file) are a few solutions to a similar problem, see if it could help – Kaneda Apr 27 '21 at 18:14
  • 1
    I really don't know it's the real problem here, but can you try switching `:` for `=` in your `application.properties` entries? – Vitor Cavalcanti Apr 27 '21 at 18:16
  • Is `sping` in `application.properties` a typo for `spring`? – Luke Woodward Apr 27 '21 at 20:43
  • properties file doees have possibility to separate key and value with `=` or `"`. See documentation: https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load%28java.io.Reader%29 – Lubo Apr 27 '21 at 22:04

1 Answers1

0

Thanks for your suggestion. The answer is what Luke Woodward propose... in the file application.properties. Typo Error.

Sping.mvc.prefix:/WEB-INF/jsp/ vs spring.mvc.view.prefix:/WEB-INF/jsp/

I've also tried with : and = and both work.

Thanks for your support appreciated.

Mike
  • 19
  • 3