Deploying a spring boot war on jetty9.4.6 with no URI in the war available - spring-boot

I follow the spring boot reference document to make an executable and deployable war in 2 steps:
in pom file, make a war package and make spring-boot-starter-tomcat scope
provided
make the Application class extends
SpringBootServletInitializer and override configure method.
then copy the war file to {jetty_home}/webapps.
I tried restart the jetty server and it seems the war was loaded with below info
2017-07-24 11:16:35.740:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext#6e1ec318{/abc-0.1,file:///tmp/jetty-0.0.0.0-8080-abc-0.1.war-_abc-0.1-any-4452702112804908874.dir/webapp/,AVAILABLE}{/abc-0.1.war}
Visitin {jetty_server_ip}:8080/abc-0.1 shows "Directory: /abc-0.1/" while visit any URL in the war returns a 404 error.
What am I doing wrong? Please guide.

The WebApp's "context path" is set to /abc-0.1 in your deployed instance.
You will only be able to access that webapp on {host}/abc-0.1/.
Assuming that you have no other contexts (webapps) deployed, then you have nothing answering at {host}/abc/ and will always get 404 for {host}/abc/ prefixed URLs.

Related

Deploy a war of Spring Boot application to the local Tomcat server: 404 response [duplicate]

This question already has answers here:
Tomcat 10.0.4 doesn't load servlets (#WebServlet classes) with 404 error [duplicate]
(2 answers)
Closed 1 year ago.
I generated a simple Greeting web application using Spring Initializr and choose war as the packaging type. Starting it from the terminal with mvn spring-boot:run and pointing my browser to http://localhost:8080/greeting returns the expected response.
I followed this article for the deployment steps and modified pom.xml so that to avoid including version numbers in the generated war:
<build>
<finalName>${artifactId}</finalName>
<plugins>
...
</build>
I build the war as usual with mvn clean installand got the expected demo-spring-web.war which I copied/pasted inside the apache-tomcat-10.0.4/webapp folder.
Then I started the Tomcat bu running catalina.sh run from the Tomcat bin folder.
Tomcat started and displayed the demo-spring-web.war to be successfully deployed:
11-Apr-2021 18:24:36.414 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR
Deployment of web application archive [/Users/serguei/soft/apache-tomcat-10.0.4/webapps/demo-spring-web.war] has finished in [1,286] ms
But when I tried to access the deployed application at localhost:8080/demo-spring-web/greeting, it returned 404 status.
What's wrong with that?
You must declare a run class that extends SpringBootServletInitializer, for deploy in war mode.Like this :
#SpringBootApplication public class AppTomcat extends SpringBootServletInitializer {
}
The default prepared/initialized application from spring initializer contains main() method initializing the application so that it can run in a stand alone mode and can be tested quickly.
In case you want to deploy it to another container you should make a servlet initializing the application.
So you should be extending the class having main method with SpringBootServletInitializer and remove main method.
The "mvn clean package" will fail if you have plugin "org.springframework.boot" in the .
I think following above two steps will make the built war deployable in external tomcat.
I had read an article some times back, may be that can also help: https://www.baeldung.com/spring-boot-war-tomcat-deploy

Spring boot 2 in a war file and to deploy in a stand alone tomcat, cannot redirect

I'm new in using Spring-boot 2.1.0,
I'm setting up a new Spring-boot 2.1.0 web project with maven, in some reasons my front page is JSP, and I package the project into a war file.
Then I deploy the war file in a stand alone Tomcat 8.0.
I package the war file with the commond mvn clean package -DskipTest=true.
The problem is:
The war package name is marpt.
login page can access by url http://localhost:8096/marpt, but when I login, action redirect failed, it takes out a 404 error.
I have googled many articles, most are base on Spring-boot 1.x.x version;
I tried to exclude embeded-tomcat in POM file;
And also I tried to config server.servlet.context-path=/marpt in the application.properties file, but it's failed to redirect again, and <%#include file="../../pages/share/partial/sidebar.jsp" %> failed too, only can use <jsp:include flush="true" page="/pages/share/partial/sidebar.jsp" />
I have upload the project to github: click here
I hope some guys can help me to fix it out, thanks very much!

Deploying spring boot executable jar on jboss but not as a war ,so that other applications can invoke as an api

I want to deploy an executable jar file on to jboss server, so that other application written in c/c++ can invoke it through workflow by passing the arguments to the executable jar file.
I have googled and found examples where war is deployed by making it restful webservice, but I could not find any such example where an executable jar file is deployed on jboss.
Appreciate your help
Regards,
Kiran Kumar
You can not deploy the spring boot executable jar file in Jboss. You need tweak your application to some extent for it to work on JBoss.
1. Add jboss-web.xml file src/main/webapp/WEB-INF folder, provide application context there.
<jboss-web>
<context-root>YOUR_APP_ROOT</context-root>
</jboss-web>
Set below spring property in your yml/props file.
server.servlet-path = /*

Spring Maven rest web service - What is the URL when deploying on real web server?

I followed this tutorial https://spring.io/guides/gs/rest-service/ by creating maven project in intellij, addind pom.xml etc. Then I run on localhost exactly as written in the tutorial and all works:
http://localhost:8080/greeting
When greeting came from the annotation of method in the controller #RequestMapping("/greeting").
Then I made JAR artifact & deployed it to Tomact on 'real server' (Elastic beanstalk environment running EC2 instance on AWS).
I got from AWS the base URL of my webserver running Tomact. What is now the suffix to my service? This is NOT working:
http://someEnvironmentName.elasticbeanstalk.com/greeting
EDIT: How I made the artifact JAR
In intellij I can compile & run maven project and then test it in localhost. So what I did:
Right click on the project name->Open Module Settings->Artifacts->Add->Jar
Build->Build Artifacts->Selecting the Jar from above
Maybe I need to build WAR? And how to deal with the POM.xml? Now my pom is exactly as in the linked tutorial.
Thanks,
If you use spring-boot, you donĀ“t need a tomcat because spring include an embedded tomcat. Only you run the application with Maven. So, the advantage of spring-boot is not dependent on an application server and using other containers such as Docker.
Do you put the port in the call to your webserver?
On the other hand, check your server logs to see if there are any problem.
Solution (Thanks to #JBNizet suggestion):
Follow this link http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
Modify the Application.java file
Modify the pom.xml (By adding one more dependency)
Then if you are using Intellij IDE under Build->Build Artifacts will be automatically option for WAR file.
Just deploy to AWS elasticbeanstalk instance running EC2 in the usual way. The URL is:
http://someEnvironmentName.elasticbeanstalk.com/greeting

Placeholder in banner.txt are not replaced when deploying war file

I've built a spring boot application and I'm trying to customize the banner to display the version of my application.
After reading the documentation, I've managed to create a banner.txt in the classpath and added the ${application.formatted-version} placeholder inside.
I've also managed to create a manifest file (using Gradle) containing the Implementation-Version.
Everything works fine when executing a jar file directly but when creating a war file, the banner is displayed but the version placeholder is not replaced.
After a bit of debugging, this method seems to be the source of the problem
org.springframework.boot.ResourceBanner.getApplicationVersion()
When running a war file, the call to
sourcePackage.getImplementationVersion() always return null
The manifest file is located at the root of the war file /META-INF/MANIFEST.MF
The application is deployed in a standalone tomcat 8.0.15
Any idea of what's wrong ?
It's a bug/limitation in Tomcat. It fails to find the /META-INF/MANIFEST.MF from an exploded WAR file which causes its ClassLoader to define the package with a null implementation version. This has been fixed in Tomcat, but the fix hasn't made it into a release yet. It'll be in 8.0.25.
There's some more information in this Spring Boot issue and this is the change that was made to Tomcat if you're interested.

Resources