Problems accessing REST endpoints from Springboot application deployed on Tomcat - java

I am developing a springboot REST application with Eclipse, but I have a problem deploying it to Tomcat 10.0.22. When I run my application from the IDE the endpoints are working fine, they returns me the correct JSONs but when I try to access them from my server they throw a 404 error.
I am packaging it as war. I have created the project from https://start.spring.io/ setting Spring web dependency, java 18 and packaging war. I imported it to eclipse as an existing maven project.
To be sure that I deployed it correctly I had created a jsp file and load it as index.jsp and it is showing correctly on the deployed server and the IDE.
I have tried to restart the proyect, change the java version in both, export the proyect as jar, to deploy it on another tomcat version, to extend SpringBootServletInitializer from the main class and override the confirm method, without the method implemented and without extending it from anywhere.
I don't understand why when I deploy it to the Tomcat server from the Tomcat manager the endpoint calls are throwing a 404 error. I think that is possible that Tomcat is not loading Springboot libraries, because I do not see the console Spring initializing message when I start the server from console, but I do not know how to solve this or if it is what is happening. Can anyone help me please.
This is my main class, TestApplication.java:
package com.testing.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
This is my servlet initializer application, ServletInitializer.java:
package com.testing.test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TestApplication.class);
}
}
This is my controller, UserController.java:
package com.testing.test.controllers;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class UserController {
#PostMapping("/test/User")
public String user(#RequestParam(name="id", defaultValue = "NO_ID_RECEIVED") String id) {
return String.format("The user ID is: %s",id);
}
}
This is my 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.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.testing</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</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>
The mentioned index.jsp:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>Let's see if it deploys</h2>
</body>
</html>
EDIT: Because I have had a questions about the structure below this I am appending a picture of it.
Project folder structure

Just to be sure have you put your JSP files under web-content and not under WEB-INF because in Eclipse the files are not accessed there by the server.
And one more thing try to check server location and see whether Tomcat is installed in the correct server location and it is showing in your Eclipse,if not try changing your server location to the location where Tomcat is installed and restart your server.

Related

Simple Spring Boot Project is giving 404 Error

I am learning Spring Boot but I am not able to execute the basic "Hello World" program. I have built the basic project using https://start.spring.io/ and updated the code as per below code snippets:
Spring Boot Main Class:
package com.rohit.springboot.practice.selfspringboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
#ComponentScan(basePackages = "com.rohit.springboot.practice.selfspringboot")
public class SelfSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SelfSpringBootApplication.class, args);
}
}
Controller Class:
package com.rohit.springboot.practice.selfspringboot;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class ThisWorldSpringContainer {
#RequestMapping(method = RequestMethod.GET, value = "/hello-world")
public String getWelcome() {
return "Hello World";
}
}
POM.xml file:
<?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.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.rohit.springboot.practice</groupId>
<artifactId>self-spring-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>self-spring-boot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</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>
Error:
Message: The requested resource [/hello-world] is not available
I know this question has been asked by multiple people but i have gone through those answers and tried those given answers but didn't work.
Technologies used are Java 8, Tomcat 9, Spring Boot 2.6.6 etc.
Kindly help.
Since you don't have the Tomcat dependency, I'm implying that you want your application to run in a standalone Tomcat instance. Also, given your comment, I believe you're working on either Eclipse or Spring Tools Suite (Which is the same, really).
With that, it seems your problem is the lack of a packaging method. Tomcat needs the code its going to run in a package. This package is a zip-like file with .war extension. Maven, the program that handles the dependencies of your project according to the pom.xml file, can package it in either war of jar format. Since you are running it in an external Tomcat, you want the war extension. So please, add the following line to your pom.xml file. It has to be in the same level as <name>:
<packaging>war</packaging>
Then, update your project (Alt + F5, check your project and hit OK) then try running your project again. You should see an stylish "SPRING" output in your console.
Now, since you are running this externally, you need to specify the name of the project, so you should call your endpoint with
http://localhost:8080/<your_project_name_here>/hello-world
I advise you to check this new change in Spring Boot 2.6 :
PathPattern Based Path Matching Strategy for Spring MVC
In this release, the default strategy for matching request paths against registered Spring MVC handler mappings has changed from AntPathMatcher to PathPatternParser.
If you need to switch the default strategy back to AntPathMatcher, you can set the property spring.mvc.pathmatch.matching-strategy to ant-path-matcher as in the line below to add in the file application.properties :
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
I encountered the same issue of HTTP 404 error when upgrading to Spring Boot 2.6 and adding this property solved my problem and should solve yours.
I have modified your code as below:
#RequestMapping
#RestController
public class ThisWorldSpringContainer {
#GetMapping(value = "/hello-world")
public String getWelcome() {
return "Hello World";
}
}
I thinking you are missing
#Requestmapping
in classlevel

Jar file not working in target folder but working in project folder

When I run the project in STS, it's working fine. All the pages in the webapp folder are loading in the browser. But when I build the project and run the JAR file (folder: D:\SpringBoot Projects\DemoExample\target) and go to the page URL, I'm getting Whitelabel error.
In another project I used spring security- In that project the login page is loading fine, but all the JSP pages in the webapp folder are not loading just like the above example.
While trying to solve this problem, I moved the JAR file from target folder to project folder (D:\SpringBoot Projects\DemoExample) and again ran the JAR file, now the JSP pages are loading fine. The JSP pages are only loading in that folder, if I moved the file to another folder, the pages are not loading.
I want to make sure that I can run the JAR file from any folder.
POM File:
<?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.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.project</groupId>
<artifactId>DemoExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>DemoExample</name>
<description>Project</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.37</version>
</dependency>
</dependencies>
<build>
<outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
<testOutputDirectory>${basedir}/${target.dir}/test-classes</testOutputDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Main Class:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoExampleApplication {
public static void main(String[] args) {
SpringApplication.run(DemoExampleApplication.class, args);
}
}
Controller:
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
#org.springframework.stereotype.Controller
public class Controller {
#RequestMapping("/")
public String home() {
return "home.jsp";
}
}
JSP File:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hello
</body>
</html>
Project Structure
Running Jar file in target folder
Result after running Jar file in target folder
Running Jar in project folder
Result after running Jar file in project folder

Spring boot: 404 error when calling JSP using controller

I'm getting the following error when running my project using Spring Tool Suite,
But in case my problem is I have already added the appropriate dependencies to pom.XML file. So what could be the problem?
My pom.XML file dependencies as follows,
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
My controller ApplicationController.java as follows,
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class ApplicationController {
#RequestMapping("/")
public String Welcome() {
return "welcomepage";
}
}
My vives are in src/main/webapp/WEB-INF/view/welcomepage.jsp you can look the tree view below,
And I have already changed the application.properties file as well. But still, I can't understand what is wrong.
My application.properties file as follows,
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
I just print hello in My welcomepage.jsp,
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hello
</body>
</html>
Looks like you was very close to the working application. The main issue in your code is in <scope>provided</scope> for your Jasper dependency.
And also looks like you are running your code from eclipse IDE through the main method.
Long story short:
If you would like to run your application through the main method in MyApplication.java then just remove scope provided for the Jasper.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
Or you can run your application exactly in that state like you have right now from the console:
mvn clean spring-boot:run
But I suggest to remove this scope so you could be able to run your code from IDE and from console. In addition to that looks like spring-boot-starter-tomcat dependency is redundant (it must be available within spring-boot-starter-web). In a nutshell please try to use following pom file:
<?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 http://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.1.3.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</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>
</dependencies>
</project>
Hope my answer will help you.
You may also need to add this in pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
UPDATE 1:
JSP Limitation
When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.
With Jetty and Tomcat, it should work if you use war packaging. An
executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.
Undertow does not support JSPs.
Creating a custom error.jsp page does not override the default view
for error handling. Custom error pages should be used instead.
Scope
compile This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
runtime This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
Also, Try to change the Following in tomcat-embed-jasper
Remove <scope>provided</scope> OR change the scope to compile <scope>compile</scope>
JSP Limitations
Spring Boot JSP 404
I was able to generate a jar from my application and then run it with java -jar myapp.jar But I only managed to run this jar with the version below spring-boot-starter-parent:
MyApp/pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
I researched in:
Spring Boot JSP 404

Spring boot return error 404 in Jboss

I have a sample Spring boot application. It works in Tomcat server but when i generate a war and deploy it in jboss server(7.1.1) i have 404 error.
this is my restController example :
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class HelloWorldController {
#RequestMapping(value="/test")
public String sayHello() {
return "Hello Spring Boot!!";
}
}
and this is my main class :
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
#SpringBootApplication
public class MainApp extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainApp.class);
}
}
i added an application.properties file and i added in it this line :
server.contextPath = /*
my jbos-web.xml is like this :
> <?xml version="1.0" encoding="UTF-8"?> <!-- this is really not
> needed... you can just build (or rename WAR file to)
> spring-boot-jboss.war
> --> <!DOCTYPE jboss-web> <jboss-web> <context-root>/test</context-root> </jboss-web>
and finally my pom.xml is as follow :
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.boraji.tutorial.springboot</groupId>
<artifactId>spring-boot-hello-world-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<java.version>1.7</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
i run the applciation by using this url :
http://localhost:8080/test/test but a 404 error was returned.
Thank you for your help.
I had the same problem on JBoss EAP 6.4 / spring boot 1.5 and what fixed it was to add this property
server.servlet-path=/*
as explained in this post : Deploying spring boot on JBOSS EAP 6.1
It worked fine without this property on JBoss EAP 7.1 though.
Your jboss-web.xml should be located in scr/main/webapp/WEB-INF/ then Jboss will use it at the start and use your defined context-root.
Add ComponentScan annotation on your MainApp class.
Probably your #RestController annotation was not found by spring component scanner
#SpringBootApplication
#ComponentScan(basePackages = {"com.blabla.*"})
public class MainApp extends SpringBootServletInitializer {
...
}
I'm not sure what exactly you are trying to achieve by using below property
server.contextPath = /*
But, if you want to have root context path for your application then it has to be some string value instead of astrike (which represents a pattern). And, actually this is not allowed. If I used same property while using tomcat server. Tomcat throws below error while registering web module
2018-08-23 21:26:58.500 ERROR 13612 --- [ost-startStop-1] org.apache.tomcat.util.modeler.Registry : Error registering Tomcat:j2eeType=WebModule,name=//localhost/*,J2EEApplication=none,J2EEServer=none
If you are trying to access url as
http://localhost:8080/test/test
Then, update property file with below
server.contextPath = /test
Otherwise, don't add this property in application.properties file, and you can access
http://localhost:8080/test

Initial springboot starter project setup - facing issue

I am trying to make a simple spring web application using Spring boot starter package provided. I am able to display 'Hello World' into console, but when I am trying to open localhost:(port), it is showing me . I am using JRE 8. Tried using JDK8 but also gives me same error. Do we have to use JDK or JRE ?
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jul 02 21:58:01 MDT 2018
There was an unexpected error (type=Not Found, status=404).
No message available
I am trying to resolve this issue from from last 2 days but I am stuck at this!.
Please find below images and code which I have in my system.
Project Structure
Spring Starter Project Application .java
package com.gami.mvc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
#SpringBootApplication
public class SpringStarterProjectApplication extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringStarterProjectApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringStarterProjectApplication.class, args);
System.out.println("Hello World");
}
}
Pom.Xml file
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gami.mvc</groupId>
<artifactId>springStarterProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springStarterProject</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<!-- This is a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Tomcat embedded container -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Optional, test for static content, bootstrap CSS -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Contoller. java
package com.gami.mvc;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
public class WelcomeController {
// inject via application.properties
#Value("${welcome.message:test}")
private String message = "Hello World";
#RequestMapping("/")
public String welcome(Map<String, Object> model) {
model.put("message", this.message);
return "welcome";
}
}
Application.properties
server.port=8456
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
welcome.message: Hello Gami
Error receiving when running the application
Error Message
Please any help is really appreciate!
Thank you
Hardik Gami
Console Image
Console msg after hitting to local host
Java Build Path Error
Java Build Path - Eclipse Java Build Path of Project
Spring will search for classes annotated with #Controller on the configured search path, without this annotation spring won't pick up your controller class.
#Controller
public class WelcomeController { ... }
Need to annotate your class with #RestController, or this will search for the welcome.jsp
JRE will not have the Compiler. Use JDK, which will have development tools like javac, javap etc.

Categories