faced 'Spring Security & whitelabel Error 404' at the very first step - spring-boot

I just started making
Springboot starter project with gradle
first of all, i can't understand why i see security log-in page even when i set config permitAll
and secondly, i see 404 error after i log-in correctly
this is my SecurityConfig
package config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
#Configuration
#EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
//super.configure(http);
http.authorizeRequests()
.anyRequest().permitAll();
}
}
this is the controller
package notice;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class ApiNoticeController {
#GetMapping("/api/notice")
public String noticeSting() {
return "notice";
}
}
dependencies
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'org.springframework.security:spring-security-test'
}
console
2022-03-23 18:50:34.733 INFO 27256 --- [ main] com.example.demo.PracticeApplication : Starting PracticeApplication using Java 17.0.1 on DESKTOP-JBB51IM with PID 27256 (C:\Users\user1\Desktop\CRUD\practice\bin\main started by user1 in C:\Users\user1\Desktop\CRUD\practice)
2022-03-23 18:50:34.740 INFO 27256 --- [ main] com.example.demo.PracticeApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-23 18:50:36.429 INFO 27256 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-03-23 18:50:36.453 INFO 27256 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8 ms. Found 0 JPA repository interfaces.
2022-03-23 18:50:37.521 INFO 27256 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-03-23 18:50:37.538 INFO 27256 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-03-23 18:50:37.538 INFO 27256 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-23 18:50:37.773 INFO 27256 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-03-23 18:50:37.774 INFO 27256 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2922 ms
2022-03-23 18:50:38.067 INFO 27256 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-03-23 18:50:38.415 INFO 27256 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-03-23 18:50:38.508 INFO 27256 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-03-23 18:50:38.614 INFO 27256 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.5.Final
2022-03-23 18:50:39.009 INFO 27256 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-03-23 18:50:39.252 INFO 27256 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-03-23 18:50:39.781 INFO 27256 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-03-23 18:50:39.801 INFO 27256 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-03-23 18:50:39.866 WARN 27256 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-03-23 18:50:40.609 INFO 27256 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: ****
2022-03-23 18:50:40.934 INFO 27256 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure any request
2022-03-23 18:50:41.124 INFO 27256 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-03-23 18:50:41.145 INFO 27256 --- [ main] com.example.demo.PracticeApplication : Started PracticeApplication in 7.185 seconds (JVM running for 9.471)
2022-03-23 18:50:48.680 INFO 27256 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-23 18:50:48.680 INFO 27256 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-23 18:50:48.681 INFO 27256 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2022-03-23 18:50:49.157 WARN 27256 --- [nio-8080-exec-1] o.a.c.util.SessionIdGeneratorBase : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [397] milliseconds.
it worked well at first, returning URL "http://localhost:8080/api/notice" & String "notice"
but suddenly not working...
What I know and saw is that I used #RestController so i don't need html view resolver...
i also tried with configuration -
// super.configure(http);
super.configure(http);
both...didn't work

Sorry it was a stupid mistake.... as you can see in the package name, i set the package path wrong. thanks everybody for reading

Related

Problems trying to work around WebSecurityConfigurerAdapter deprecation using Spring Boot 2.7.5

When updating spring boot version 2.7.5 I noticed that the WebSecurityConfigurerAdapter class was deprecated in this version.
I followed the steps as described in section 2.2 on article on Baeldung
to customize my application's authentication rules, but the filterChain method is not even being called during application startup, as with the "configure" function using spring boot version 2.2.3.
Can anyone help me?
Below I show the before and after of my changes.
Before
#Configuration
#EnableWebSecurity
#EnableGlobalMethodSecurity(prePostEnabled = true)
class SecurityConfiguration : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
val tokenTypes: List<TokenType> = mapper.readValue(jsonTokenTypes, Array<TokenType>::class.java).toList()
http.csrf().disable()
.authorizeRequests()
.antMatchers("/graphql").permitAll()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilterBefore(
AuthFilter.create(keySet, tokenTypes),
RequestHeaderAuthenticationFilter::class.java
)
}
}
After
#Configuration
#EnableWebSecurity
#EnableGlobalMethodSecurity(prePostEnabled = true)
class SecurityConfiguration() {
#Value("\${vehicle.op.jwk.key-set}")
private lateinit var keySet: List<String>
#Value("\${vehicle.op.jwt.token-types}")
private lateinit var jsonTokenTypes: String
protected val mapper = jacksonObjectMapper()
#Bean
fun filterChain(http: HttpSecurity): SecurityFilterChain {
val tokenTypes: List<TokenType> = mapper.readValue(jsonTokenTypes, Array<TokenType>::class.java).toList()
http.csrf().disable()
.authorizeRequests()
.antMatchers("/graphql").permitAll()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilterBefore(
AuthFilter.create(keySet, tokenTypes),
RequestHeaderAuthenticationFilter::class.java
)
return http.build()
}
Application starts up normally, as shown in the log below:
13:22:33: Executing 'bootRun -Dspring.profiles.active=homolog'...
> Task :checkApolloVersions UP-TO-DATE
> Task :generateMainServiceApolloSources NO-SOURCE
> Task :compileKotlin UP-TO-DATE
> Task :compileJava NO-SOURCE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :bootRunMainClassName UP-TO-DATE
> Task :bootRun __ __ _ _ ___________ | \/ | ___ | |__ (_)___ \ \ \ \ | |\/| |/ _ \| '_ \| | / / \ \ \ \ | | | | (_) | |_) | | / / ) ) ) ) |_| |_|\___/|_.__/|_|/_/ / / / /
===========================/_/_/_/ :: my_application :: (vlatest)
2022-12-06 13:22:37.312 INFO 29076 --- [ main] i.company.op.vehicle.VehicleApplicationKt : Starting VehicleApplicationKt using Java 11.0.16 on DESKTOP-07SSK0A with PID 29076 (C:\company\GitHub\my_application\build\classes\kotlin\main started by admin in C:\company\GitHub\my_application) 2022-12-06 13:22:37.316 INFO 29076 --- [ main] i.company.op.vehicle.VehicleApplicationKt : No active profile set, falling back to 1 default profile: "default" 2022-12-06 13:22:37.816 INFO 29076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2022-12-06 13:22:37.883 INFO 29076
--- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 62 ms. Found 4 JPA repository interfaces. 2022-12-06 13:22:38.065 INFO 29076 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=c811da27-aff3-39ab-b4ee-d6bb20987e72 2022-12-06 13:22:38.602 INFO 29076 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http) 2022-12-06 13:22:38.611 INFO 29076 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-12-06 13:22:38.612 INFO 29076 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68] 2022-12-06 13:22:38.718 INFO 29076 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-12-06 13:22:38.719 INFO 29076 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1351 ms 2022-12-06 13:22:38.872 INFO 29076 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2022-12-06 13:22:39.037 INFO 29076 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2022-12-06 13:22:39.507 INFO 29076 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT(*) FROM public.liq_db_changelog_lock 2022-12-06 13:22:39.519 INFO 29076 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT(*) FROM public.liq_db_changelog_lock 2022-12-06 13:22:39.520 INFO 29076 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT LOCKED FROM public.liq_db_changelog_lock WHERE ID=1 2022-12-06 13:22:39.533 INFO 29076 --- [ main] l.lockservice.StandardLockService : Successfully acquired change log lock 2022-12-06 13:22:39.545 INFO 29076 --- [ main] liquibase.changelog.DatabaseChangeLog : Reading resource: db/changelog/202210050955-changelog.sql 2022-12-06 13:22:39.552 INFO 29076 --- [ main] liquibase.changelog.DatabaseChangeLog : Reading resource: db/changelog/202210051005-changelog.sql 2022-12-06 13:22:39.561 INFO 29076 --- [ main] liquibase.changelog.DatabaseChangeLog : Reading resource: db/changelog/202210141724-changelog.sql 2022-12-06 13:22:39.569 INFO 29076 --- [ main] liquibase.changelog.DatabaseChangeLog : Reading resource: db/changelog/202210310837-changelog.sql 2022-12-06 13:22:39.653 INFO 29076 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT MD5SUM FROM public.liq_db_changelog WHERE MD5SUM IS NOT NULL LIMIT 1 2022-12-06 13:22:39.657 INFO 29076 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT COUNT(*) FROM public.liq_db_changelog 2022-12-06 13:22:39.659 INFO 29076 --- [ main] l.c.StandardChangeLogHistoryService : Reading from public.liq_db_changelog 2022-12-06 13:22:39.659 INFO 29076 --- [ main] liquibase.executor.jvm.JdbcExecutor : SELECT * FROM public.liq_db_changelog ORDER BY DATEEXECUTED ASC, ORDEREXECUTED ASC 2022-12-06 13:22:39.683 INFO 29076 --- [ main] l.lockservice.StandardLockService : Successfully released change log lock 2022-12-06 13:22:39.831 INFO 29076 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2022-12-06 13:22:39.911 INFO 29076 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.12.Final 2022-12-06 13:22:40.122 INFO 29076 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final} 2022-12-06 13:22:40.242 INFO 29076
--- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect 2022-12-06 13:22:40.651 INFO 29076 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2022-12-06 13:22:40.658 INFO 29076 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2022-12-06 13:22:42.695 INFO 29076 --- [ main] s.b.a.g.s.GraphQlWebMvcAutoConfiguration : GraphQL endpoint HTTP POST /graphql 2022-12-06 13:22:43.217 WARN 29076 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 6e231318-c400-4c42-bb52-079a429bd04a
This generated password is for development use only. Your security configuration must be updated before running your application in production.
2022-12-06 13:22:43.411 INFO 29076 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter#4e92c6c2, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#71a18feb, org.springframework.security.web.context.SecurityContextPersistenceFilter#26aecf31, org.springframework.security.web.header.HeaderWriterFilter#693f9ab5, org.springframework.security.web.csrf.CsrfFilter#197d6cc9, org.springframework.security.web.authentication.logout.LogoutFilter#286f8e90, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#327fd5c9, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#3d1b6816, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#66032b8d, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#70a9f4b7, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#1abacff3, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#4a3d4cd2, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#7c1a5092, org.springframework.security.web.session.SessionManagementFilter#3f04847e, org.springframework.security.web.access.ExceptionTranslationFilter#76e56b17, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#169f4152] 2022-12-06 13:22:43.478 INFO 29076 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9090 (http) with context path '' 2022-12-06 13:22:43.488 INFO 29076
--- [ main] i.company.op.vehicle.VehicleApplicationKt : Started VehicleApplicationKt in 6.557 seconds (JVM running for 6.906)
Originally my application validates only the Bearer Token given in the request header, and after upgrade spring boot version now it requires a user/password authentication.

SpringBoot does not detect template of Thymeleaf

I started learning Thymeleaf templating with SpringBoot and my learning path was blocked by some implicit issue i could not find....
The issue is: SpringBoot app does not see template, although:
Controller looks like
Project structure includes /templates:
All required dependencies are in place:
Spring Boot log:
2022-11-13 22:21:13.196 INFO 20644 --- [ main]
com.coffeeshop.Application : Starting Application using
Java 11.0.10 on LAPTOP-O6B9USVI with PID 20644
(C:\Dev\Java\Projects\coffeeshop\build\classes\java\main started by
User in C:\Dev\Java\Projects\coffeeshop) 2022-11-13 22:21:13.196 INFO
20644 --- [ main] com.coffeeshop.Application :
No active profile set, falling back to 1 default profile: "default"
2022-11-13 22:21:13.588 INFO 20644 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
JPA repositories in DEFAULT mode. 2022-11-13 22:21:13.604 INFO 20644
--- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 23 ms. Found 1 JPA
repository interfaces. 2022-11-13 22:21:14.106 INFO 20644 --- [
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized
with port(s): 8081 (http) 2022-11-13 22:21:14.106 INFO 20644 --- [
main] o.apache.catalina.core.StandardService : Starting service
[Tomcat] 2022-11-13 22:21:14.106 INFO 20644 --- [ main]
org.apache.catalina.core.StandardEngine : Starting Servlet engine:
[Apache Tomcat/9.0.64] 2022-11-13 22:21:14.184 INFO 20644 --- [
main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring
embedded WebApplicationContext 2022-11-13 22:21:14.184 INFO 20644 ---
[ main] w.s.c.ServletWebServerApplicationContext : Root
WebApplicationContext: initialization completed in 957 ms 2022-11-13
22:21:14.278 INFO 20644 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [name: default] 2022-11-13 22:21:14.309 INFO
20644 --- [ main] org.hibernate.Version :
HHH000412: Hibernate ORM core version 5.6.9.Final 2022-11-13
22:21:14.309 INFO 20644 --- [ main]
org.hibernate.cfg.Environment : HHH000205: Loaded
properties from resource hibernate.properties:
{hibernate.temp.use_jdbc_metadata_defaults=false,
hibernate.bytecode.use_reflection_optimizer=false} 2022-11-13
22:21:14.404 INFO 20644 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.1.2.Final} 2022-11-13 22:21:14.466 INFO 20644
--- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-11-13 22:21:14.796 INFO 20644 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-11-13 22:21:14.905 INFO 20644 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start
completed. 2022-11-13 22:21:14.921 INFO 20644 --- [ main]
o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using
JtaPlatform implementation:
[org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-11-13 22:21:14.921 INFO 20644 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default' 2022-11-13
22:21:15.094 WARN 20644 --- [ main]
JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is
enabled by default. Therefore, database queries may be performed
during view rendering. Explicitly configure spring.jpa.open-in-view to
disable this warning 2022-11-13 22:21:15.298 INFO 20644 --- [
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on
port(s): 8081 (http) with context path '' 2022-11-13 22:21:15.298
INFO 20644 --- [ main] com.coffeeshop.Application
: Started Application in 2.409 seconds (JVM running for 2.7)
When i check http://localhost:8081/home I got "home" string only.
Replace #RestController with #Controller. You cannot use #RestController because #RestController automatically adds #ResponseBody and Spring will only attempt to look up a view if #ResponseBody is not present.
This should fix your problem
#Controller
public class AppController {
#GetMapping("/")
public String viewHomePage() {
return "home";
}
}

Postman - 401 unauthorized status | Spring Boot

I prepared very simple REST APi.
I am trying to do requests with postman but i get 401 Unauthorized. No matter what kind request it is. I have Windows 11 system, Java 11, Postman Version 9.8.2
Postman:
application.properties file:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/students
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
Spring Application:
#SpringBootApplication(exclude = {UserDetailsServiceAutoConfiguration.class})
public class StudentsmanagerApplication {
public static void main(String[] args) {
SpringApplication.run(StudentsmanagerApplication.class, args);
}
Controller class:
#RestController
#RequestMapping("/student")
public class StudentController {
private StudentService studentService;
#GetMapping
public ResponseEntity<List<Student>> getAllStudents() {
List<Student> students = studentService.findAllStudent();
return new ResponseEntity<>(students, HttpStatus.OK);
}
#GetMapping("find/{id}")
public ResponseEntity<Student> getAllStudentsById(#PathVariable Long id) {
Student student = studentService.findStudentById(id);
return new ResponseEntity<>(student, HttpStatus.OK);
}
#PostMapping
public ResponseEntity<Student> addEmployee(#RequestBody Student student) {
Student newStudent = studentService.addStudent(student);
return new ResponseEntity<>(newStudent, HttpStatus.CREATED);
}
#PutMapping("/{id}")
public ResponseEntity<Student> updateStudent(#PathVariable Long id, #RequestBody Student
student) {
Student updatedStudent = studentService.updateStudent(id, student);
return new ResponseEntity<>(updatedStudent, HttpStatus.UPGRADE_REQUIRED);
}
#DeleteMapping("/{id}")
public ResponseEntity<?> deleteStudent(#PathVariable Long id) {
studentService.deleteStudent(id);
return new ResponseEntity<>(HttpStatus.OK);
}
Service class:
#Service
public class StudentService {
private StudentRepository studentRepository;
public Student addStudent(Student student) {
student.setStudentCode(UUID.randomUUID().toString());
return studentRepository.save(student);
}
public List<Student> findAllStudent() {
return studentRepository.findAll();
}
public Student updateStudent(Long id, Student student) {
Student studentById = studentRepository
.findById(id).orElseThrow(() -> new StudentNotFoundException("Student by id
" + " doesn't Exist"));
studentById.setName(student.getName());
studentById.setLastName(student.getLastName());
studentById.setEmail(student.getEmail());
studentById.setPhone(student.getPhone());
return studentRepository.save(studentById);
}
public Student findStudentById(Long id) {
return studentRepository
.findById(id).orElseThrow(() -> new StudentNotFoundException("Student
doesn't exist "));
}
public void deleteStudent(Long id) {
studentRepository.deleteById(id);
}
Spring logs:
2022-01-08 10:53:19.661 INFO 20120 --- [ main] p.s.s.StudentsmanagerApplication : Starting StudentsmanagerApplication using Java 11.0.13 on LAPTOP-9F9MO24J with PID 20120 (C:\Users\mkord\IdeaProjects\studentsmanager\target\classes started by mkord in C:\Users\mkord\IdeaProjects\studentsmanager)
2022-01-08 10:53:19.661 INFO 20120 --- [ main] p.s.s.StudentsmanagerApplication : No active profile set, falling back to default profiles: default
2022-01-08 10:53:20.539 INFO 20120 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-01-08 10:53:20.596 INFO 20120 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 50 ms. Found 1 JPA repository interfaces.
2022-01-08 10:53:21.262 INFO 20120 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-01-08 10:53:21.278 INFO 20120 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-01-08 10:53:21.278 INFO 20120 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-01-08 10:53:21.422 INFO 20120 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-01-08 10:53:21.422 INFO 20120 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1684 ms
2022-01-08 10:53:21.662 INFO 20120 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-01-08 10:53:21.703 INFO 20120 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.3.Final
2022-01-08 10:53:21.856 INFO 20120 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-01-08 10:53:21.976 INFO 20120 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-01-08 10:53:22.336 INFO 20120 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-01-08 10:53:22.352 INFO 20120 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2022-01-08 10:53:22.968 INFO 20120 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-01-08 10:53:22.984 INFO 20120 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-01-08 10:53:23.032 WARN 20120 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-01-08 10:53:23.824 INFO 20120 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#36931450, org.springframework.security.web.context.SecurityContextPersistenceFilter#451a4187, org.springframework.security.web.header.HeaderWriterFilter#6db04a6, org.springframework.security.web.csrf.CsrfFilter#630c3af3, org.springframework.security.web.authentication.logout.LogoutFilter#4866e0a7, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#66d44581, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#4ac0d49, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#74919649, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#2ea4e762, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#5c215642, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#1317ac2c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#7d07e04e, org.springframework.security.web.session.SessionManagementFilter#426913c4, org.springframework.security.web.access.ExceptionTranslationFilter#38197e82, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#5a07ae2f]
2022-01-08 10:53:23.914 INFO 20120 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-01-08 10:53:23.930 INFO 20120 --- [ main] p.s.s.StudentsmanagerApplication : Started StudentsmanagerApplication in 4.851 seconds (JVM running for 6.309)
2022-01-08 10:59:13.709 INFO 20120 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-01-08 10:59:13.709 INFO 20120 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-01-08 10:59:13.709 INFO 20120 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 0 ms
2022-01-08 10:59:13.941 WARN 20120 --- [nio-8080-exec-2] o.a.c.util.SessionIdGeneratorBase : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [184] milliseconds.
Thank You in advance for any suggestion

Spring boot H2 console returns 404

I have a simple Springboot application and it's up running. I am able to call REST endpoints through Postman. However, when I try to access the console using http://localhost:8080/h2 it keeps returning 404.
2020-08-29 08:06:37.577 INFO 6507 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2020-08-29 08:06:37.644 INFO 6507 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2020-08-29 08:06:37.645 INFO 6507 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-08-29 08:06:37.677 INFO 6507 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-08-29 08:06:37.787 INFO 6507 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-08-29 08:06:38.247 INFO 6507 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-08-29 08:06:38.737 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2020-08-29 08:06:38.738 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2020-08-29 08:06:38.741 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2020-08-29 08:06:38.813 INFO 6507 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080
2020-08-29 08:06:38.813 INFO 6507 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
2020-08-29 08:06:38.816 INFO 6507 --- [ main] c.v.t.c.m.tenant.discovery.Application : Started Application in 3.4 seconds (JVM running for 3.661)
2020-08-29 08:06:48.527 WARN 6507 --- [ctor-http-nio-2] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://localhost:8080/h2]: Response status 404
2020-08-29 08:23:07.301 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Retrograde clock change detected (housekeeper delta=29s626ms), soft-evicting connections from pool.
2020-08-29 08:57:06.586 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=33m59s284ms).
2020-08-29 09:35:49.699 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper
My application.yml file looks like this.
spring:
datasource:
url: jdbc:h2:mem:test
platform: h2
username: sa
password:
driverClassName: org.h2.Driver
hikari:
maximum-pool-size: 50
h2:
console:
enabled: true
path: /h2
settings:
web-allow-others: true
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
server:
port: 8080
As per your logs, I found that, you are using an embedded server, other than tomcat, i.e, spring-boot-starter-reactor-netty that comes along with spring webflux dependency.
H2ConsoleAutoConfiguration will not be executed for spring webflux & netty(reactor based), as H2 console will only be available to servlet based applications. So, you have to configure H2 server manually in this spring boot application, with spring webflux & netty.
Sample H2Server (working code):
package com.example.springbootnettyserver;
import org.h2.tools.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import static org.h2.tools.Server.createWebServer;
#Component
public class H2ServerManual {
Logger log = LoggerFactory.getLogger(H2ServerManual.class);
private Server webServer;
#Value("${h2-server.port}")
Integer h2ConsolePort;
#EventListener(ContextRefreshedEvent.class)
public void start() throws java.sql.SQLException {
log.info("starting h2 console at port "+ h2ConsolePort);
this.webServer = createWebServer("-webPort", h2ConsolePort.toString(),
"-tcpAllowOthers").start();
System.out.println(webServer.getURL());
}
#EventListener(ContextClosedEvent.class)
public void stop() {
log.info("stopping h2 console at port "+h2ConsolePort);
this.webServer.stop();
}
}
Note: org.h2.tools.Server class will be resolved only when h2 dependency is added without scope of runtime. (remove scope element in dependency)
In application.properties, you will add port details for h2 server like
h2-server:
port: 8081
Here, now, the H2 console will be available at http://localhost:8081
Following properties can be removed
# h2:
# console:
# enabled: true
# path: /h2
# settings:
# web-allow-others: true
For Reference: https://github.com/donthadineshkumar/webflux-netty-server-h2-example.git

Spring boot: I am getting whitelabel error pae instead of view

I am writing spring boot application with spring MVC and H2 in memory database. I have a controller with mapping /posts on findAllPosts() method which returns post.jsp view. But when i run application and hit localhost:8080/posts it shows error page. In console it also shows mapping done for /posts.
Controller class-
package com.H2DatabaseDemo.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.H2DatabaseDemo.model.Post;
import com.H2DatabaseDemo.services.PostService;
#Controller
public class H2DemoController {
#Autowired
private PostService postService;
#RequestMapping("/posts")
public String findAllPost(Model model)
{
List<Post> thePosts=postService.findAllPost();
model.addAttribute("posts",thePosts);
return "posts";
}
}
Appication class-
package com.H2DatabaseDemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
public class H2DatabaseDemoApplication {
public static void main(String[] args) {
SpringApplication.run(H2DatabaseDemoApplication.class, args);
}
}
property file-
spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.datasource.url=jdbc:h2:mem:h2demo-app
spring.mvc.view.prefix: /WEB-INF/view/
spring.mvc.view.suffix: .jsp
stack trace-
:: Spring Boot :: (v2.0.4.RELEASE)
2018-09-16 09:19:50.379 INFO 12868 --- [ main] c.H.H2DatabaseDemoApplication : Starting H2DatabaseDemoApplication on DESKTOP-7NILS0D with PID 12868 (D:\springCourse\H2DatabaseDemo\target\classes started by Mrugesh in D:\springCourse\H2DatabaseDemo)
2018-09-16 09:19:50.384 INFO 12868 --- [ main] c.H.H2DatabaseDemoApplication : No active profile set, falling back to default profiles: default
2018-09-16 09:19:50.459 INFO 12868 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3d299e3: startup date [Sun Sep 16 09:19:50 IST 2018]; root of context hierarchy
2018-09-16 09:19:52.000 INFO 12868 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$74090544] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-09-16 09:19:52.796 INFO 12868 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-09-16 09:19:52.833 INFO 12868 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-09-16 09:19:52.834 INFO 12868 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.32
2018-09-16 09:19:52.849 INFO 12868 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_171\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_171/bin/server;C:/Program Files/Java/jre1.8.0_171/bin;C:/Program Files/Java/jre1.8.0_171/lib/amd64;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\nodejs\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Microsoft VS Code\bin;C:\Users\Mrugesh\AppData\Roaming\npm;C:\Users\Mrugesh\AppData\Local\Microsoft\WindowsApps;C:\Users\Mrugesh\AppData\Local\GitHubDesktop\bin;C:\eclipse;;.]
2018-09-16 09:19:53.018 INFO 12868 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-09-16 09:19:53.018 INFO 12868 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2562 ms
2018-09-16 09:19:53.160 INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-09-16 09:19:53.162 INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet webServlet mapped to [/console/*]
2018-09-16 09:19:53.167 INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-09-16 09:19:53.167 INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-09-16 09:19:53.168 INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-09-16 09:19:53.168 INFO 12868 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-09-16 09:19:53.408 INFO 12868 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-09-16 09:19:53.806 INFO 12868 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-09-16 09:19:53.876 INFO 12868 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-09-16 09:19:53.905 INFO 12868 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-09-16 09:19:54.036 INFO 12868 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-09-16 09:19:54.038 INFO 12868 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-09-16 09:19:54.085 INFO 12868 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-09-16 09:19:54.280 INFO 12868 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-09-16 09:19:54.962 INFO 12868 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#93824eb'
2018-09-16 09:19:54.965 INFO 12868 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-09-16 09:19:55.623 INFO 12868 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-16 09:19:55.918 INFO 12868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3d299e3: startup date [Sun Sep 16 09:19:50 IST 2018]; root of context hierarchy
2018-09-16 09:19:55.974 WARN 12868 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-09-16 09:19:56.017 INFO 12868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/posts]}" onto public java.lang.String com.H2DatabaseDemo.controller.H2DemoController.findAllPost(org.springframework.ui.Model)
2018-09-16 09:19:56.027 INFO 12868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-09-16 09:19:56.028 INFO 12868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-09-16 09:19:56.060 INFO 12868 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-16 09:19:56.060 INFO 12868 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-16 09:19:56.366 INFO 12868 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-09-16 09:19:56.370 INFO 12868 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-09-16 09:19:56.378 INFO 12868 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-09-16 09:19:56.610 INFO 12868 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-09-16 09:19:56.614 INFO 12868 --- [ main] c.H.H2DatabaseDemoApplication : Started H2DatabaseDemoApplication in 6.721 seconds (JVM running for 7.372)
2018-09-16 09:20:06.742 INFO 12868 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-09-16 09:20:06.742 INFO 12868 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-09-16 09:20:06.884 INFO 12868 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 142 ms
2018-09-16 09:20:07.138 INFO 12868 --- [nio-8080-exec-1] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
Over the controller method add RequestMapping("/")
Please add these dependencies in your pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>

Resources