Initial springboot starter project setup - facing issue


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





Oh yes, .jsp file is inside webapp/Web-INF/Jsp.. but it is present and its name is welcome.jsp. I have tried opening sample spring boot webapplication in eclipse to run, but always shows me Error Message as mentioned above
– Hardik Gami
Jul 3 at 4:15





Please check the error stacktrace in your IDE console to get exception details.
– Amith Kumar
Jul 3 at 4:22





you do not @RestController annotation on your welcomecontroller.
– akshaya pandey
Jul 3 at 4:28





@AmithKumar , I have updated the question with console image. I don't see any error exception. Also it prints out Hello world perfectly fine
– Hardik Gami
Jul 3 at 4:36





You need to annotate your controller class with @Controller or @RestController (read their docs for more info) to let Spring discover them.
– sn42
Jul 3 at 4:52


@Controller


@RestController




3 Answers
3



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


@Controller
public class WelcomeController { ... }





Hello Alien -> I did add @Controller over WelcomeController.java class, and when I ran, it gave me an error that no Compiler found. When checking buildpath - I have JRE clicked. I have updated the question with the image too.. Webpage error when accesing localhost. Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Mon Jul 02 22:44:03 MDT 2018 There was an unexpected error (type=Internal Server Error, status=500). No Java compiler available for configuration options compilerClassName: [null] and compiler: [null]
– Hardik Gami
Jul 3 at 4:49





refer this mkyong.com/spring-boot/…
– Alien
Jul 3 at 4:52





I am using mykyong spring boot Hello world example itself. Just have changed package name, other than that - Syntax , html and css file are the same. When I add <dependency> <groupId>org.eclipse.jdt.core.compiler</groupId> <artifactId>ecj</artifactId> <version>4.6.1</version> <scope>provided</scope> </dependency> in the pom.xml, it should an Exclamatory mark at the bottom of the project and wont compile.
– Hardik Gami
Jul 3 at 4:57



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages