Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Spring Boot files doesn't work when put in tomcat

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have two project developed using Spring Boot. Basically developed the back-end code developed and tested via Rest API.

Now, we have done the front end html and other pages separately.

Now we are not sure how to integrate this project as web application and deploy automatically via Maven in Tomcat

Need to know the project structure for web application project for Spring Boot
Where to place the jsp, javascript, html, css, log4.properties file in spring boot
How to automatically bundle the project and deploy as a war so that we can deploy in any tomcat externally instead of going for a Spring Boot Embedded tomcat.

Tried by placing all the files in external tomcat webapps folder by creating war file but the attempt got failed.

Need advise.
 
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
It depends on what you specify in your application.properties
this is a snippet of a application.properties that I use:


ofcourse you have to adjust it to fit your needs, the most important for you are the first to lines (comment not counted).

Then your structure would be:


I hope that clarifies your question
 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your kind reply. Need the clarification on the below

1. Do we need to create the web-inf folder?
2. Do we need to create SpringBootServletInitializer  class ? (Ex: https://stackoverflow.com/questions/27405713/running-code-after-spring-boot-starts)
3. Do we need to have component scan or just placing the classes files inside the war file would be sufficient ?
4. Do we need to create WebConfig.java and do any configurations to make it work?

Thanks in advance.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. Do we need to create the web-inf folder?  


Yes you have to create a WEB-INF folder in the webapp folder, note it's WEB-INF, not web-inf.

2. Do we need to create SpringBootServletInitializer  class ? (Ex: https://stackoverflow.com/questions/27405713/running-code-after-spring-boot-starts)  


You can create a custon servletInitializer, but I never needed to, it always has bin sufficient to let the MainClass extend the SprinBootServletInitializer.

3. Do we need to have component scan or just placing the classes files inside the war file would be sufficient ?  


You do need to annotate your MainClass with you can at a ComponentScan to it   and annotate your controllerClasses with

4. Do we need to create WebConfig.java and do any configurations to make it work?


I have  a WebMvcConfiguration annotated with but all it does is extending the WebMvcConfigurerAdapter and some securityConfigurationClasses.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To illustrate some codesnippets.

Mainclass:


WebMvcConfig:

 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Demesmaecker...It is nothing but Awesome Reply.....Thanks a lot....

I would like to hear more answers for many of my questions. I like the way you explain...

Would you be like to respond via email ? Please kindly let me know.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that I'm opossed against giving some one on one feedback, but I think it's more beneficiary for everyone if questions and answer are posted on the forum. Someone else might have the same questions and find the answers in your post.
 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right...Thank you So Much.....
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic