简体   繁体   中英

Application.properties not being found

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM