Spring boot can't mapp to the links in HTML - spring-boot

I am using Spring boot starter project with maving pluging,
spring boot can't know the links in my HTML templates.
this is my controller :
#Controller
#EnableAutoConfiguration
#ComponentScan
public class Demoproject2Application {
#RequestMapping("/")
public String home() {
return "/html/Authentification";
}
}
and this is the Authentification.HTML:
<!DOCTYPE html>
<html>
<head>
<title>Authentification</title>
<link rel="stylesheet" type="text/css" href="css/style2.css" />
and this is the error :
2015-02-19 14:29:58.749 INFO 5136 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat]. [localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2015-02-19 14:29:58.749 INFO 5136 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2015-02-19 14:29:58.774 INFO 5136 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 25 ms
2015-02-19 14:29:59.086 WARN 5136 --- [nio-8090-exec-2] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/css/style2.css] in DispatcherServlet with name 'dispatcherServlet'
2015-02-19 14:30:00.813 WARN 5136 --- [nio-8090-exec-4]o.s.web.servlet.PageNotFound
here is a snapshot of the hierarchy of my project :
https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/11011221_811266045595770_3095529215585152558_n.jpg?oh=a51a1196651bd62c81a76679869c1bdd&oe=558FD62B&gda=1431221666_e2d5202a80db81801ed9903c48014130

If you didn't changed any defaults it should be served when you put it into src/main/resources/static/css/style2.css. Please see official documentation.

Related

Use thymeleaf template of another project

There seems to be problem if using thymeleaf for multiple projects.
Let's say I have a spring application in project 2 & the controller in project 1. With proper #ComponentScan defined, the application able to display the view/html in my template folder. But once I added the thymeleaf-layout-dialect maven dependency, it failed with "There was an unexpected error (type=Not Found, status=404)." error.
My projects:
The prj1 pom.xml:
<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>macrohard.org</groupId>
<artifactId>prj1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
</dependencies>
</project>
The prj2 pom.xml:
<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>macrohard.org</groupId>
<artifactId>prj2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>macrohard.org</groupId>
<artifactId>prj1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
The hello-world.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>HW</title>
</head>
<body>
Hello World!!
</body>
</html>
The App2 in prj2:
package prj2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
#ComponentScan(basePackages = { "prj1"} )
public class App2 {
public static void main(String[] args) {
SpringApplication.run(App2.class, args);
}
}
The Controller1 in prj1
package prj1.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
#RestController
#RequestMapping(value="/api")
public class Controller1 {
// this can be run by App2 & App1
#GetMapping(value="/hello")
public String hello() {
return "hello world";
}
// this can be run by App1 only
#GetMapping(value="/hello2")
public ModelAndView hello2() {
ModelAndView mav = new ModelAndView();
mav.setViewName("hello-world");
return mav;
}
}
As in Controller1, The "api/hello" can be requested successfully because it doesn't involve the template. But for the "api/hello2" request, it unable to render the hello-world.html. Here are the error stacks:
2019-07-02 22:21:28.758 INFO 19680 --- [ main] prj2.App2 : Started App2 in 1.89 seconds (JVM running for 2.454)
2019-07-02 22:21:51.807 INFO 19680 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-07-02 22:21:51.807 INFO 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-07-02 22:21:51.807 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.multipart.support.StandardServletMultipartResolver#2ded92
2019-07-02 22:21:51.810 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : No LocaleResolver 'localeResolver': using default [AcceptHeaderLocaleResolver]
2019-07-02 22:21:51.811 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : No ThemeResolver 'themeResolver': using default [FixedThemeResolver]
2019-07-02 22:21:51.814 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : No RequestToViewNameTranslator 'viewNameTranslator': using default [DefaultRequestToViewNameTranslator]
2019-07-02 22:21:51.817 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : No FlashMapManager 'flashMapManager': using default [SessionFlashMapManager]
2019-07-02 22:21:51.817 DEBUG 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2019-07-02 22:21:51.817 INFO 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 10 ms
2019-07-02 22:21:51.829 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : GET "/api/hello2", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2019-07-02 22:21:51.834 TRACE 19680 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.web.servlet.ModelAndView prj1.web.Controller1.hello2()
2019-07-02 22:21:51.843 TRACE 19680 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Arguments: []
2019-07-02 22:21:51.851 DEBUG 19680 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/webp, image/apng, application/signed-exchange;v=b3, application/xml;q=0.9, */*;q=0.8]
2019-07-02 22:21:51.851 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'hello-world'; URL [hello-world]]
2019-07-02 22:21:51.851 DEBUG 19680 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : View name 'hello-world', model {}
2019-07-02 22:21:51.853 DEBUG 19680 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Forwarding to [hello-world]
2019-07-02 22:21:51.857 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : "FORWARD" dispatch for GET "/api/hello-world", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2019-07-02 22:21:51.860 TRACE 19680 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 3 interceptors
2019-07-02 22:21:51.862 DEBUG 19680 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
2019-07-02 22:21:51.862 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : No view rendering, null ModelAndView returned.
2019-07-02 22:21:51.862 DEBUG 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "FORWARD" dispatch, status 404, headers={}
2019-07-02 22:21:51.864 DEBUG 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND, headers={}
2019-07-02 22:21:51.865 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2019-07-02 22:21:51.865 TRACE 19680 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 matching mappings: [{ /error, produces [text/html]}, { /error}]
2019-07-02 22:21:51.866 TRACE 19680 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-07-02 22:21:51.875 TRACE 19680 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Arguments: [org.apache.catalina.core.ApplicationHttpRequest#6fdc83, org.apache.catalina.connector.ResponseFacade#119a78b]
2019-07-02 22:21:51.885 DEBUG 19680 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
2019-07-02 22:21:51.886 TRACE 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$StaticView#216e30]
2019-07-02 22:21:51.908 DEBUG 19680 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 404, headers={}
I am certain that it is due to thymeleaf-layout-dialect, because if I remove it from pom.xml everything work fine.
The problem is I need it to layout thymeleaf page. How to display the template in another different project from spring application?
As you have published an example project, I can't follow the issue :/
Are you sure you did not just confuse the "hello world" messages from the controller with the message from the template?
When I modify: \prj1\src\main\resources\templates\hello-world.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>HW</title>
</head>
<body>
Hello World!! (from Template in prj1)!
</body>
</html>
I had to add this into pom.xml of prj1 because of some weird classpath issue:
(the thymeleaf-layout-dialect lib you use seems to bring in an additional thymeleaf jar - did not investigate that)
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
When I run prj2 app and call: http://localhost:8080/api/hello3 or http://localhost:8080/api/hello2
I get:
Hello World!! (from Template in prj1)!
Which is what we want?
When I call: http://localhost:8080/api/hello
I get an error because of some not found template ("hello world" is of course not a template file).
So I'm not sure why it does not work for you :/
I'm not sure how this works without that dependency. The controllers that work with templates can return the template name directly. And you are implementing rest controllers which suggest different defaults than required for working with templates (like the content types).
So a controller that would invoke a template looks like (this is my way of doing it, can't claim I know its the only one):
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
#Controller
public class MyController {
#Autowired
public MyController() {
}
#RequestMapping("/hello-world")
public String hello(Model model) {
model.addAttribute("someKey", "someValue");
return "hello-world"; // this is the template name in src/main/resources
}
}
And this way it is also possible to have controllers / templates bundled in one jar and use them in a different spring boot application as dependencies. Since it is all classpath based (there is a property to configure this: spring.thymeleaf.prefix) this just worked for me.
I think the reason really is your rest controller - which might confuse things a bit.

Using different packages for Controllers when using in Spring Boot

I am new in Spring boot.I trying to access the controller url but i didn't get any response from them.
We are followed spring boot project structure as per document.
I have used componentscan annotation and added scanBasePackageClasses in SpringBootApplication annotation.But still same.
HomeController :-
package com.main.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class HomeController {
#RequestMapping(value="/home",method=RequestMethod.GET)
public String home() {
System.out.println("home");
return "home";
}
}
GAppsApplication.java:-
package com.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import com.main.controllers.HomeController;
#ComponentScan({"com.main.controllers"})
#SpringBootApplication(scanBasePackageClasses={HomeController.class})
public class GAppsApplication {
public static void main(String[] args) {
SpringApplication.run(GAppsApplication.class, args);
}
}
For your reference i shared below logs
logs:-
2018-08-28 08:26:16.404 INFO 8172 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#58b9d6, org.springframework.security.web.context.SecurityContextPersistenceFilter#525747, org.springframework.security.web.header.HeaderWriterFilter#1638752, org.springframework.security.web.csrf.CsrfFilter#324c61, org.springframework.security.web.authentication.logout.LogoutFilter#14a6743, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#12d6ce4, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#1837d01, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#eda2d2, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#4a5109, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#4bb38c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#12205be, org.springframework.security.web.session.SessionManagementFilter#2e4343, org.springframework.security.web.access.ExceptionTranslationFilter#1a81a58, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#12e7437]
2018-08-28 08:26:16.558 INFO 8172 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-08-28 08:26:16.592 INFO 8172 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-08-28 08:26:16.594 INFO 8172 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-08-28 08:26:16.600 INFO 8172 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-08-28 08:26:16.638 INFO 8172 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-08-28 08:26:16.642 INFO 8172 --- [ restartedMain] c.main.GAppsApplication : Started GAppsApplication in 5.153 seconds (JVM running for 5.734)
2018-08-28 08:27:11.961 INFO 8172 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-08-28 08:27:11.961 INFO 8172 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-08-28 08:27:11.980 INFO 8172 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 19 ms
Change your controller to like below :
#RestController
#RequestMapping("/home")
public class HomeController {
#GetMapping
public String home() {
System.out.println("home");
return "home";
}
}
As your base package is com.main, so any package within com.main will automatically be scanned.
You don't need to put any special annotation to scan.

SpringBoot, Thymeleaf, Gradle: not accessing static resources, css not showing

I have tried so many things at this point, but my css will not show on my pages. this is my thymeleaf page:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title th:text="${title}">Default Title</title>
<link th:href="#{/css/styles.css}" rel="stylesheet" type="text/css" />
</head>
this is the error i get when I load this page, which i assume it important:
**2018-04-11 05:57:08.425 WARN 7904 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/css/styles.css] in DispatcherServlet with name 'dispatcherServlet'**
I have my static resources in the PROPER folder, like this (image link):
Folders path
sources>main>resources>static and then another css folder, which i did add to the #{}.
I have searched and search everywhere for answers, I even added this to my WebMcvConfigurerAdapter class, like I kept seeing:
#Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}
This is my current one(im using interceptors and stuff, just disregard that part):
#Configuration
#EnableWebMvc
public class MyAppConfig extends WebMvcConfigurerAdapter {
#Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new ProjectManagerInterceptor());
}
}
This is my build.gradle file, in case it helps:
buildscript {
ext {
springBootVersion = '1.5.10.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'org.launchcode'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.session:spring-session')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
bootRun {
addResources = true
}
I have another project that also uses static resources like i'm trying to do, and it works perfectly. I will post some of it's code and information, in case it might help.
Working application's information
CONSOLE WHEN I LOAD A PAGE WITH STATIC RESOURCES:
2018-04-11 05:53:15.553 DEBUG 7448 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/css/bootstrap.css]
2018-04-11 05:53:15.554 DEBUG 7448 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /css/bootstrap.css
2018-04-11 05:53:15.554 DEBUG 7448 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/css/techjobs.css]
2018-04-11 05:53:15.554 DEBUG 7448 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /css/techjobs.css
2018-04-11 05:53:15.556 DEBUG 7448 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/css/bootstrap.css]
2018-04-11 05:53:15.556 DEBUG 7448 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/css/bootstrap.css] are [/**]
2018-04-11 05:53:15.558 DEBUG 7448 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/css/bootstrap.css] are {}
2018-04-11 05:53:15.559 DEBUG 7448 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/css/bootstrap.css] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver#3f0bd4d8]]] and 1 interceptor
2018-04-11 05:53:15.560 DEBUG 7448 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/css/bootstrap.css] is: -1
2018-04-11 05:53:15.580 DEBUG 7448 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/js/bootstrap.js]
2018-04-11 05:53:15.581 DEBUG 7448 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /js/bootstrap.js
2018-04-11 05:53:15.582 DEBUG 7448 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/js/bootstrap.js]
2018-04-11 05:53:15.582 DEBUG 7448 --- [nio-8080-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/js/bootstrap.js] are [/**]
2018-04-11 05:53:15.582 DEBUG 7448 --- [nio-8080-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/js/bootstrap.js] are {}
2018-04-11 05:53:15.582 DEBUG 7448 --- [nio-8080-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/js/bootstrap.js] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver#3f0bd4d8]]] and 1 interceptor
2018-04-11 05:53:15.582 DEBUG 7448 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/js/bootstrap.js] is: -1
2018-04-11 05:53:15.592 DEBUG 7448 --- [nio-8080-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/css/techjobs.css]
2018-04-11 05:53:15.594 DEBUG 7448 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/css/techjobs.css] are [/**]
2018-04-11 05:53:15.595 DEBUG 7448 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/css/techjobs.css] are {}
2018-04-11 05:53:15.595 DEBUG 7448 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/css/techjobs.css] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver#3f0bd4d8]]] and 1 interceptor
2018-04-11 05:53:15.595 DEBUG 7448 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/css/techjobs.css] is: -1
HTML:
<head th:fragment="head">
<!-- Bootstrap stylesheets and script -->
<link th:href="#{/css/bootstrap.css}" rel="stylesheet" />
<link th:href="#{/css/techjobs.css}" rel="stylesheet" />
<script type="text/javascript" th:src="#{/js/bootstrap.js}"></script>
<title th:text="'TechJobs' + ${title == null ? '' : ' :: ' + title}">TechJobs</title>
</head>
FOLDER SETUP:
Working app's folder paths
If there are any questions dont hesitate to ask! I'm really bummed out about this, so much time
I just found the answer to my own question, so I'm going to leave this hear for anyone who might find it.
Spring Boot not serving static content
I had an unnecessary #EnableWebMvc annotation, that I took out, and my resources worked :D!

Restriction for localhost is not working in SpringBoot web security

Restriction for localhost is not working in SpringBoot web security.By commenting the configure method content, URL(http://127.0.0.1:8080/SPPA/runSPPAJob) is working otherwise error comes.
Code:
#EnableWebSecurity
#Configuration
public class AllowOnlyLocalhostFilter extends WebSecurityConfigurerAdapter
{
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/SPPA/**").
access("hasIpAddress('127.0.0.1')").anyRequest().authenticated();
}
}
Web Page Response:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 29 16:05:46 IST 2017
There was an unexpected error (type=Forbidden, status=403).
Access Denied
Log:
2017-05-29 16:05:46.482 INFO 3644 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/SPPA] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-05-29 16:05:46.482 [http-nio-8080-exec-1] INFO
o.a.c.c.C.[.[localhost].[/SPPA]-Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-05-29 16:05:46.485 INFO 3644 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-05-29 16:05:46.485 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization started
2017-05-29 16:05:46.684 INFO 3644 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 199 ms
2017-05-29 16:05:46.684 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization completed in 199 ms

Spring boot web application starts dispatcherServlet 2 times

When it receives first request it initiates dispatcherServlet 2 times. Then all requests to this app is served 2 times. It's happening on Linux only not on Windows. Log entries below:
[2016-01-20 10:52:39.125] boot - 3367 INFO [http-nio-8090-exec-1] --- [/]: Initializing Spring FrameworkServlet 'dispatcherServlet'
[2016-01-20 10:52:39.125] boot - 3367 INFO [http-nio-8090-exec-1] --- [/]: Initializing Spring FrameworkServlet 'dispatcherServlet'
[2016-01-20 10:52:39.129] boot - 3367 INFO [http-nio-8090-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization started
[2016-01-20 10:52:39.129] boot - 3367 INFO [http-nio-8090-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization started
[2016-01-20 10:52:39.156] boot - 3367 INFO [http-nio-8090-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization completed in 27 ms
[2016-01-20 10:52:39.156] boot - 3367 INFO [http-nio-8090-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization completed in 27 ms
App has dependency to: spring-boot-starter-tomcat, spring-boot-starter-web
It main class and controller:
#RestController
class LogController {
public static final Logger LOG = LoggerFactory.getLogger(LogController.class);
#RequestMapping("/getErrors")
public Map<String, String> getErrors() {
//call to methods
}
}
#EnableConfigurationProperties
#SpringBootApplication
#EnableScheduling
//#EnableWebMvcSecurity
public class LogAppConfiguration {
public static void main(String[] args) {
SpringApplication.run(LogAppConfiguration.class, args);
}
}
I have tried removing the EmbeddedServletContainerFactory bean(not shown above). Still it occurs.

Resources