Spring Boot not loading views from templates












0














My Spring Boot project is not loading view from src/main/resources/templates/login.html. However it does load view from src/main/resources/static/index.html.



Here is my project structure:



enter image description here



I have added simple <a> tag for opening my login page in my index.html



    <div>
<a class="btn" href="login">Login</a>
</div>


LoginController:



@RequestMapping("/login")
public String showLogin() {
System.out.println("Login method called");
return "login";
}


This method doesn't get called. Moreover, I have seen many tutorials showing you don't need to add your view in static folder, just add your views in templates folder and Spring Boot will automatically pick it.



But it seems that Spring Boot is not picking views from templates folder and shows white label error page.



I am not using jsp pages instead I am on Thymelead template.



application.properties



server.servlet.context-path=/hisservices

server.port=8081

welcome.message: Welcome to the HIS Services Dashboard


WelcomeController: <- This shows index.html page



// 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";
}


Do I need to add explicit mapping for templates folder?










share|improve this question






















  • If the controller isn't called, that has nothing to do with views. Move your application class to the ... securejwt package.
    – JB Nizet
    Dec 28 '18 at 7:59








  • 1




    move you HisservicesJwtApplication.java to outer/upper layer package i.e. com.skm.hisservice.secueejwt
    – user3145373 ツ
    Dec 28 '18 at 8:36










  • please post code of HisservicesJwtApplication.java
    – user3145373 ツ
    Dec 28 '18 at 8:42
















0














My Spring Boot project is not loading view from src/main/resources/templates/login.html. However it does load view from src/main/resources/static/index.html.



Here is my project structure:



enter image description here



I have added simple <a> tag for opening my login page in my index.html



    <div>
<a class="btn" href="login">Login</a>
</div>


LoginController:



@RequestMapping("/login")
public String showLogin() {
System.out.println("Login method called");
return "login";
}


This method doesn't get called. Moreover, I have seen many tutorials showing you don't need to add your view in static folder, just add your views in templates folder and Spring Boot will automatically pick it.



But it seems that Spring Boot is not picking views from templates folder and shows white label error page.



I am not using jsp pages instead I am on Thymelead template.



application.properties



server.servlet.context-path=/hisservices

server.port=8081

welcome.message: Welcome to the HIS Services Dashboard


WelcomeController: <- This shows index.html page



// 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";
}


Do I need to add explicit mapping for templates folder?










share|improve this question






















  • If the controller isn't called, that has nothing to do with views. Move your application class to the ... securejwt package.
    – JB Nizet
    Dec 28 '18 at 7:59








  • 1




    move you HisservicesJwtApplication.java to outer/upper layer package i.e. com.skm.hisservice.secueejwt
    – user3145373 ツ
    Dec 28 '18 at 8:36










  • please post code of HisservicesJwtApplication.java
    – user3145373 ツ
    Dec 28 '18 at 8:42














0












0








0







My Spring Boot project is not loading view from src/main/resources/templates/login.html. However it does load view from src/main/resources/static/index.html.



Here is my project structure:



enter image description here



I have added simple <a> tag for opening my login page in my index.html



    <div>
<a class="btn" href="login">Login</a>
</div>


LoginController:



@RequestMapping("/login")
public String showLogin() {
System.out.println("Login method called");
return "login";
}


This method doesn't get called. Moreover, I have seen many tutorials showing you don't need to add your view in static folder, just add your views in templates folder and Spring Boot will automatically pick it.



But it seems that Spring Boot is not picking views from templates folder and shows white label error page.



I am not using jsp pages instead I am on Thymelead template.



application.properties



server.servlet.context-path=/hisservices

server.port=8081

welcome.message: Welcome to the HIS Services Dashboard


WelcomeController: <- This shows index.html page



// 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";
}


Do I need to add explicit mapping for templates folder?










share|improve this question













My Spring Boot project is not loading view from src/main/resources/templates/login.html. However it does load view from src/main/resources/static/index.html.



Here is my project structure:



enter image description here



I have added simple <a> tag for opening my login page in my index.html



    <div>
<a class="btn" href="login">Login</a>
</div>


LoginController:



@RequestMapping("/login")
public String showLogin() {
System.out.println("Login method called");
return "login";
}


This method doesn't get called. Moreover, I have seen many tutorials showing you don't need to add your view in static folder, just add your views in templates folder and Spring Boot will automatically pick it.



But it seems that Spring Boot is not picking views from templates folder and shows white label error page.



I am not using jsp pages instead I am on Thymelead template.



application.properties



server.servlet.context-path=/hisservices

server.port=8081

welcome.message: Welcome to the HIS Services Dashboard


WelcomeController: <- This shows index.html page



// 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";
}


Do I need to add explicit mapping for templates folder?







spring spring-boot






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 28 '18 at 7:50









Faizan MubasherFaizan Mubasher

2,19332146




2,19332146












  • If the controller isn't called, that has nothing to do with views. Move your application class to the ... securejwt package.
    – JB Nizet
    Dec 28 '18 at 7:59








  • 1




    move you HisservicesJwtApplication.java to outer/upper layer package i.e. com.skm.hisservice.secueejwt
    – user3145373 ツ
    Dec 28 '18 at 8:36










  • please post code of HisservicesJwtApplication.java
    – user3145373 ツ
    Dec 28 '18 at 8:42


















  • If the controller isn't called, that has nothing to do with views. Move your application class to the ... securejwt package.
    – JB Nizet
    Dec 28 '18 at 7:59








  • 1




    move you HisservicesJwtApplication.java to outer/upper layer package i.e. com.skm.hisservice.secueejwt
    – user3145373 ツ
    Dec 28 '18 at 8:36










  • please post code of HisservicesJwtApplication.java
    – user3145373 ツ
    Dec 28 '18 at 8:42
















If the controller isn't called, that has nothing to do with views. Move your application class to the ... securejwt package.
– JB Nizet
Dec 28 '18 at 7:59






If the controller isn't called, that has nothing to do with views. Move your application class to the ... securejwt package.
– JB Nizet
Dec 28 '18 at 7:59






1




1




move you HisservicesJwtApplication.java to outer/upper layer package i.e. com.skm.hisservice.secueejwt
– user3145373 ツ
Dec 28 '18 at 8:36




move you HisservicesJwtApplication.java to outer/upper layer package i.e. com.skm.hisservice.secueejwt
– user3145373 ツ
Dec 28 '18 at 8:36












please post code of HisservicesJwtApplication.java
– user3145373 ツ
Dec 28 '18 at 8:42




please post code of HisservicesJwtApplication.java
– user3145373 ツ
Dec 28 '18 at 8:42












2 Answers
2






active

oldest

votes


















1














IMO, you need to do package restructure.



Move main application file(HisserviceJwtApplication.java) into com.skm.hisservice.securejwt package and create new package config under com.skm.hisservice.securejwt and move SecurityConfig. No need to change another package.



By doing this, your LoginController will scan automatically by spring-boot and method showLogin would also called.



If, you want to continue with existing package structure(not advisable), then add @ComponentScan('com.skm.hisservice.securejwt.controller') into main application file.






share|improve this answer





















  • Yes that's correct. It was all about package restructuring. Thanks. I created project from Spring Boot Initializer and it created this package structure. Thanks a lot.
    – Faizan Mubasher
    Dec 28 '18 at 8:59



















0














Unless uses of Thymeleaf, Just Spring Boot could not find views from templates. You have to add following repository to your project to get solution. The way like this



main/webapp/WEB-INIF/*.html


Enter this two lines of code on file application.properties



spring.mvc.view.prefix: /WEB-INF/
spring.mvc.view.suffix: .html


Now, run the project hope the issue resolved.






share|improve this answer





















    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%2f53955276%2fspring-boot-not-loading-views-from-templates%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    IMO, you need to do package restructure.



    Move main application file(HisserviceJwtApplication.java) into com.skm.hisservice.securejwt package and create new package config under com.skm.hisservice.securejwt and move SecurityConfig. No need to change another package.



    By doing this, your LoginController will scan automatically by spring-boot and method showLogin would also called.



    If, you want to continue with existing package structure(not advisable), then add @ComponentScan('com.skm.hisservice.securejwt.controller') into main application file.






    share|improve this answer





















    • Yes that's correct. It was all about package restructuring. Thanks. I created project from Spring Boot Initializer and it created this package structure. Thanks a lot.
      – Faizan Mubasher
      Dec 28 '18 at 8:59
















    1














    IMO, you need to do package restructure.



    Move main application file(HisserviceJwtApplication.java) into com.skm.hisservice.securejwt package and create new package config under com.skm.hisservice.securejwt and move SecurityConfig. No need to change another package.



    By doing this, your LoginController will scan automatically by spring-boot and method showLogin would also called.



    If, you want to continue with existing package structure(not advisable), then add @ComponentScan('com.skm.hisservice.securejwt.controller') into main application file.






    share|improve this answer





















    • Yes that's correct. It was all about package restructuring. Thanks. I created project from Spring Boot Initializer and it created this package structure. Thanks a lot.
      – Faizan Mubasher
      Dec 28 '18 at 8:59














    1












    1








    1






    IMO, you need to do package restructure.



    Move main application file(HisserviceJwtApplication.java) into com.skm.hisservice.securejwt package and create new package config under com.skm.hisservice.securejwt and move SecurityConfig. No need to change another package.



    By doing this, your LoginController will scan automatically by spring-boot and method showLogin would also called.



    If, you want to continue with existing package structure(not advisable), then add @ComponentScan('com.skm.hisservice.securejwt.controller') into main application file.






    share|improve this answer












    IMO, you need to do package restructure.



    Move main application file(HisserviceJwtApplication.java) into com.skm.hisservice.securejwt package and create new package config under com.skm.hisservice.securejwt and move SecurityConfig. No need to change another package.



    By doing this, your LoginController will scan automatically by spring-boot and method showLogin would also called.



    If, you want to continue with existing package structure(not advisable), then add @ComponentScan('com.skm.hisservice.securejwt.controller') into main application file.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 28 '18 at 8:25









    Shaunak PatelShaunak Patel

    67549




    67549












    • Yes that's correct. It was all about package restructuring. Thanks. I created project from Spring Boot Initializer and it created this package structure. Thanks a lot.
      – Faizan Mubasher
      Dec 28 '18 at 8:59


















    • Yes that's correct. It was all about package restructuring. Thanks. I created project from Spring Boot Initializer and it created this package structure. Thanks a lot.
      – Faizan Mubasher
      Dec 28 '18 at 8:59
















    Yes that's correct. It was all about package restructuring. Thanks. I created project from Spring Boot Initializer and it created this package structure. Thanks a lot.
    – Faizan Mubasher
    Dec 28 '18 at 8:59




    Yes that's correct. It was all about package restructuring. Thanks. I created project from Spring Boot Initializer and it created this package structure. Thanks a lot.
    – Faizan Mubasher
    Dec 28 '18 at 8:59













    0














    Unless uses of Thymeleaf, Just Spring Boot could not find views from templates. You have to add following repository to your project to get solution. The way like this



    main/webapp/WEB-INIF/*.html


    Enter this two lines of code on file application.properties



    spring.mvc.view.prefix: /WEB-INF/
    spring.mvc.view.suffix: .html


    Now, run the project hope the issue resolved.






    share|improve this answer


























      0














      Unless uses of Thymeleaf, Just Spring Boot could not find views from templates. You have to add following repository to your project to get solution. The way like this



      main/webapp/WEB-INIF/*.html


      Enter this two lines of code on file application.properties



      spring.mvc.view.prefix: /WEB-INF/
      spring.mvc.view.suffix: .html


      Now, run the project hope the issue resolved.






      share|improve this answer
























        0












        0








        0






        Unless uses of Thymeleaf, Just Spring Boot could not find views from templates. You have to add following repository to your project to get solution. The way like this



        main/webapp/WEB-INIF/*.html


        Enter this two lines of code on file application.properties



        spring.mvc.view.prefix: /WEB-INF/
        spring.mvc.view.suffix: .html


        Now, run the project hope the issue resolved.






        share|improve this answer












        Unless uses of Thymeleaf, Just Spring Boot could not find views from templates. You have to add following repository to your project to get solution. The way like this



        main/webapp/WEB-INIF/*.html


        Enter this two lines of code on file application.properties



        spring.mvc.view.prefix: /WEB-INF/
        spring.mvc.view.suffix: .html


        Now, run the project hope the issue resolved.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 5:53









        Arif HosainArif Hosain

        393




        393






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53955276%2fspring-boot-not-loading-views-from-templates%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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas