Why Spring Boot 4 “custom error page” fails 404?












1















I tried to implement an own error page handling.But my page doesnt show up.
Controller:



@Controller
public class MyCustomErrorController implements ErrorController {

@RequestMapping(value = "/error", method = RequestMethod.GET)
public String handleError() {

return "error";
}

@Override
public String getErrorPath() {

return "/error";
}}


I did my own error.html file in src/main/resources/static/html.
The html folder is created by myself. Where is the problem?



<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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
</dependencies>









share|improve this question

























  • Do you have thymeleaf dependency ?

    – Mykhailo Moskura
    Nov 15 '18 at 0:52











  • no i don't use it

    – LittleProgrammer
    Nov 15 '18 at 0:53
















1















I tried to implement an own error page handling.But my page doesnt show up.
Controller:



@Controller
public class MyCustomErrorController implements ErrorController {

@RequestMapping(value = "/error", method = RequestMethod.GET)
public String handleError() {

return "error";
}

@Override
public String getErrorPath() {

return "/error";
}}


I did my own error.html file in src/main/resources/static/html.
The html folder is created by myself. Where is the problem?



<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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
</dependencies>









share|improve this question

























  • Do you have thymeleaf dependency ?

    – Mykhailo Moskura
    Nov 15 '18 at 0:52











  • no i don't use it

    – LittleProgrammer
    Nov 15 '18 at 0:53














1












1








1








I tried to implement an own error page handling.But my page doesnt show up.
Controller:



@Controller
public class MyCustomErrorController implements ErrorController {

@RequestMapping(value = "/error", method = RequestMethod.GET)
public String handleError() {

return "error";
}

@Override
public String getErrorPath() {

return "/error";
}}


I did my own error.html file in src/main/resources/static/html.
The html folder is created by myself. Where is the problem?



<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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
</dependencies>









share|improve this question
















I tried to implement an own error page handling.But my page doesnt show up.
Controller:



@Controller
public class MyCustomErrorController implements ErrorController {

@RequestMapping(value = "/error", method = RequestMethod.GET)
public String handleError() {

return "error";
}

@Override
public String getErrorPath() {

return "/error";
}}


I did my own error.html file in src/main/resources/static/html.
The html folder is created by myself. Where is the problem?



<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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope> -->
</dependency>
</dependencies>






spring spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 0:55







LittleProgrammer

















asked Nov 15 '18 at 0:49









LittleProgrammerLittleProgrammer

377




377













  • Do you have thymeleaf dependency ?

    – Mykhailo Moskura
    Nov 15 '18 at 0:52











  • no i don't use it

    – LittleProgrammer
    Nov 15 '18 at 0:53



















  • Do you have thymeleaf dependency ?

    – Mykhailo Moskura
    Nov 15 '18 at 0:52











  • no i don't use it

    – LittleProgrammer
    Nov 15 '18 at 0:53

















Do you have thymeleaf dependency ?

– Mykhailo Moskura
Nov 15 '18 at 0:52





Do you have thymeleaf dependency ?

– Mykhailo Moskura
Nov 15 '18 at 0:52













no i don't use it

– LittleProgrammer
Nov 15 '18 at 0:53





no i don't use it

– LittleProgrammer
Nov 15 '18 at 0:53












1 Answer
1






active

oldest

votes


















1














You can open your html file from static content like



localhost:8080/yourpagename


By default, Spring boot serves index.html as the root resource when accessing the root URL of a web application.



(yourhtml).html should exist under any of these paths:



src/main/resources/META-INF/resources/home.html

src/main/resources/resources/home.html

src/main/resources/static/home.html

src/main/resources/public/home.html


In order to view your error.html static page you need to return “error.html” in controller



In order to define your own static resource locations
you could use this property in application.properties or application.yml file :



spring.resources.static-locations=your own locations





share|improve this answer


























  • I swapped the error.html file out of my under folder from static to static. my structure was: statitc/html/error.html. Can't i do subfolders for static?

    – LittleProgrammer
    Nov 15 '18 at 1:12








  • 1





    You can do subfolders

    – Mykhailo Moskura
    Nov 15 '18 at 1:14






  • 1





    thank you very much i got now my error which i searched. first i must give the subfolder also back with my html file in the controller: /html/error.html

    – LittleProgrammer
    Nov 15 '18 at 1:17













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310924%2fwhy-spring-boot-4-custom-error-page-fails-404%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can open your html file from static content like



localhost:8080/yourpagename


By default, Spring boot serves index.html as the root resource when accessing the root URL of a web application.



(yourhtml).html should exist under any of these paths:



src/main/resources/META-INF/resources/home.html

src/main/resources/resources/home.html

src/main/resources/static/home.html

src/main/resources/public/home.html


In order to view your error.html static page you need to return “error.html” in controller



In order to define your own static resource locations
you could use this property in application.properties or application.yml file :



spring.resources.static-locations=your own locations





share|improve this answer


























  • I swapped the error.html file out of my under folder from static to static. my structure was: statitc/html/error.html. Can't i do subfolders for static?

    – LittleProgrammer
    Nov 15 '18 at 1:12








  • 1





    You can do subfolders

    – Mykhailo Moskura
    Nov 15 '18 at 1:14






  • 1





    thank you very much i got now my error which i searched. first i must give the subfolder also back with my html file in the controller: /html/error.html

    – LittleProgrammer
    Nov 15 '18 at 1:17


















1














You can open your html file from static content like



localhost:8080/yourpagename


By default, Spring boot serves index.html as the root resource when accessing the root URL of a web application.



(yourhtml).html should exist under any of these paths:



src/main/resources/META-INF/resources/home.html

src/main/resources/resources/home.html

src/main/resources/static/home.html

src/main/resources/public/home.html


In order to view your error.html static page you need to return “error.html” in controller



In order to define your own static resource locations
you could use this property in application.properties or application.yml file :



spring.resources.static-locations=your own locations





share|improve this answer


























  • I swapped the error.html file out of my under folder from static to static. my structure was: statitc/html/error.html. Can't i do subfolders for static?

    – LittleProgrammer
    Nov 15 '18 at 1:12








  • 1





    You can do subfolders

    – Mykhailo Moskura
    Nov 15 '18 at 1:14






  • 1





    thank you very much i got now my error which i searched. first i must give the subfolder also back with my html file in the controller: /html/error.html

    – LittleProgrammer
    Nov 15 '18 at 1:17
















1












1








1







You can open your html file from static content like



localhost:8080/yourpagename


By default, Spring boot serves index.html as the root resource when accessing the root URL of a web application.



(yourhtml).html should exist under any of these paths:



src/main/resources/META-INF/resources/home.html

src/main/resources/resources/home.html

src/main/resources/static/home.html

src/main/resources/public/home.html


In order to view your error.html static page you need to return “error.html” in controller



In order to define your own static resource locations
you could use this property in application.properties or application.yml file :



spring.resources.static-locations=your own locations





share|improve this answer















You can open your html file from static content like



localhost:8080/yourpagename


By default, Spring boot serves index.html as the root resource when accessing the root URL of a web application.



(yourhtml).html should exist under any of these paths:



src/main/resources/META-INF/resources/home.html

src/main/resources/resources/home.html

src/main/resources/static/home.html

src/main/resources/public/home.html


In order to view your error.html static page you need to return “error.html” in controller



In order to define your own static resource locations
you could use this property in application.properties or application.yml file :



spring.resources.static-locations=your own locations






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 7:13









kj007

2,72631327




2,72631327










answered Nov 15 '18 at 1:04









Mykhailo MoskuraMykhailo Moskura

868213




868213













  • I swapped the error.html file out of my under folder from static to static. my structure was: statitc/html/error.html. Can't i do subfolders for static?

    – LittleProgrammer
    Nov 15 '18 at 1:12








  • 1





    You can do subfolders

    – Mykhailo Moskura
    Nov 15 '18 at 1:14






  • 1





    thank you very much i got now my error which i searched. first i must give the subfolder also back with my html file in the controller: /html/error.html

    – LittleProgrammer
    Nov 15 '18 at 1:17





















  • I swapped the error.html file out of my under folder from static to static. my structure was: statitc/html/error.html. Can't i do subfolders for static?

    – LittleProgrammer
    Nov 15 '18 at 1:12








  • 1





    You can do subfolders

    – Mykhailo Moskura
    Nov 15 '18 at 1:14






  • 1





    thank you very much i got now my error which i searched. first i must give the subfolder also back with my html file in the controller: /html/error.html

    – LittleProgrammer
    Nov 15 '18 at 1:17



















I swapped the error.html file out of my under folder from static to static. my structure was: statitc/html/error.html. Can't i do subfolders for static?

– LittleProgrammer
Nov 15 '18 at 1:12







I swapped the error.html file out of my under folder from static to static. my structure was: statitc/html/error.html. Can't i do subfolders for static?

– LittleProgrammer
Nov 15 '18 at 1:12






1




1





You can do subfolders

– Mykhailo Moskura
Nov 15 '18 at 1:14





You can do subfolders

– Mykhailo Moskura
Nov 15 '18 at 1:14




1




1





thank you very much i got now my error which i searched. first i must give the subfolder also back with my html file in the controller: /html/error.html

– LittleProgrammer
Nov 15 '18 at 1:17







thank you very much i got now my error which i searched. first i must give the subfolder also back with my html file in the controller: /html/error.html

– LittleProgrammer
Nov 15 '18 at 1:17






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310924%2fwhy-spring-boot-4-custom-error-page-fails-404%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python