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

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!

Related

Spring Boot Maven pom.xml error

I am using Spring Boot to build an application. I downloaded initialized zip project file from start.spring.io/. When I import the project I am getting the following error. By googling I could hardly understand it is proxy or connection issue. But I am able to open the url in browser.
Some people mentioned to change in settings.xml in maven. My eclipse implicitly comes with maven so I did not install maven separately. I tried adding proxy in eclipse as well. But no luck.

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

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.

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.

Grails run-app causes error generating web.xml file and bootstrap.groovy not included in war file

I am working on an maven application. When I run it from IntelliJ, it successfully launches my application. But bootstrap.groovy file is not being read. I have created a new username to be added to DB in bootstrap and it should allow me to login to the application using that username for the first time. This is not getting invoked during the start of the program. What settings should I do to include bootstrap.groovy.
The same happens when I create a war file and deploy it in the test server. Bootstrap.grrovy is not read. To create the war file, I use mvn package in command line.
My other question with the same application is that when I do grails run-app, I get the following error: Error generating web.xml file.
What is that I am missing? Please let me know.
Well, I fixed the issue. The web.xml was created when I changed the grails dependent jar. I was using 2.3.4 in my application and my jar was incompatible as I had 2.4.3 version of the jar. Now my program is up and running! Hope this helps someone who is facing the same problem.

Cant get Spring SAML2 working

I can't seem to get saml2 working. Here is what I have done.
I downloaded the sample application from here: https://github.com/spring-projects/spring-security-saml, this was a link from their documentation: http://docs.spring.io/spring-security-saml/docs/1.0.x/reference/html/chapter-quick-start.html
1) converted the sample application 'saml2-sample' into an eclispe project: mvn eclipse:eclipse
2) built the project: mvn package
3) added the 'Dynamic Web Module` facet to the project:
Right Click on project > Properties > Project Facets
4) Run the application on the STS Server:
Right Click on project > Run As > Run on Server
Server starts up and everything looks ok in the console except the url loads with HTTP Status 404 - /spring-security-saml2-sample/ at the URL http://localhost:8080/spring-security-saml2-sample/
Please, follow these steps:
Download the project from Github as archive.
Unzip the archive.
By STS/Eclipse: File > Import > Existing Maven Projects and select as root dir {your_download_folder}/spring-security-saml-master/sample folder.
Now, you may see these errors:
Fix the pom.xml as shown in this gist.
In the end, you may also fix the MetadataController class (note that some methods have changed between versions).
The easiest way is to remove that class, otherwise you should fix it manually.
Finally, run the project as webapp.
That's all!
Annotation-based configuration
If you would like to use an annotation-based configuration, you could see this one: spring-boot-security-saml-sample.
The try to change the Spring Framework dependency to latest version's like 3.2.13 or 4.0.9. I'm able to run the application successfully with both of these dependencies. Also when you're updating spring dependencies, please make sure to change xsd version to what you're using spring version "securityContext.xml" and "saml-servlet.xml".
Fyi - I've use following versions in a pom.xml file
<properties>
<junit.version>4.12</junit.version>
<jsp-api-version>2.0</jsp-api-version>
<spring.version>4.0.9.RELEASE</spring.version>
<spring.security.version>3.2.5.RELEASE</spring.security.version>
<spring-security-saml2-core-version>1.0.0.RELEASE</spring-security-saml2-core-version>
<slf4j-log4j12-version>1.7.10</slf4j-log4j12-version>
<jstl.version>1.2</jstl.version>
</properties>

Resources