I have a Gradle, Spring Boot (web starter) application, that is built to be run either as a standalone application with the embedded container, or deployed to a container as a war.
So I from Eclipse I can run/debug the #SpringBootApplication class, and also deploy the war in Tomcat. All works fine.
Now, for some requirements, I need to know the running environment; standalone or container. Basically, we generate a MANIFEST file to the war, with a Gradle build, and refer to that file for some version/meta information. However, this would be generated only when built from Gradle. Is there any way in code I can differentiate this?
Related
I know that if we want to deploy spring boot web app on external server we should exclude the embedded
server,but what happens if we dont? Lets say Im deploying spring boot war on jboss external server,but I did not exclude tomcat server?In that case, Does spring boot uses jboss external server, or still uses embedded tomcat one?
In dual packaging scenario, ideally you should specify tomcat dependencies as provided so that you will have tomcat dependencies under WEB-INF/lib-provided rather than WEB-INF/lib. Therefore with an external server lib-provided folder will be ignored bu with a standalone spring boot application tomcat dependencies will be loaded as embedded from lib-provided folder.
Note that If you do not exclude or make provided the tomcat dependencies, external server might fail or work in inconsistence state or even can work without error in some version while failing in another version version depending on the server handling of duplicate libraries.
If you do not exclude tomcat-dependencies nor declare the dependency as provided, then deployment of war fails on wildfly 19.0.0. with java.lang.RuntimeException: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer
`
I'm struggling to learn how I go about building, packaging, and deploying a Spring REST API locally so that I can interact with it? Ideally, I'd just like to GET and POST data as practice -- specifically integrating with DynamoDB.
I've cloned this DynamoDB project and built it using mvn package so that I have a jar file. I moved the jar file to the webapp directory of Apache and started the server, but I cannot interact with the API in any way. The project is structured as follows:
Once Apache is running with the jar in the webapp directory, I've tried accessing the API at:
http://localhost:8080/
http://localhost:8080/springbootapp (from server.contextPath=/springbootapp in application.properties)
Each gives a 404 error. And yes, DynamoDB is running locally. So what do I need to do differently? How can I deploy and access this API locally?
The project you have cloned is a spring boot project, hence you can use mvn spring-boot:run to run the application locally.You can also run it by running the com.baeldung.Application class as a java application from the IDE. For more details on how to run a spring boot app you can follow this link. Spring boot parent has a dependency on the embedded tomcat, which will run the application.
Additionally if you want to deploy the application as a war the spring boot documentation shows how to do it.
I am new to spring boot and I would want to know the basics of it. I am creating a project with jHipster. When I install gulp on my system I can see the project running at port 9000. I however want to deploy the same application on my local using tomcat apache server.
Can I debug my code in java using the same server installed during the time of spring boot or do I need a separate server like apache?
From JHipster documentation "Profiles" :
If you're using Maven Wrapper (mvnw)
./mvnw package
If you're using Gradle Wrapper (mvnw)
./gradlew bootRepackage
Should produce WAR with development profile as
By default, JHipster will use the dev profile
I think you can deploy this WAR on your usual Tomcat
I have a WAR with Java Spring application, which I can deploy to a Java application server. I need to run it on a machine with JRE, but without application server, i.e. with java -jar my_application.jar.
The guide "Convert an existing application to Spring Boot" is a close match, except that I do not need to create a deployable WAR as I already have it. The existing code does not use #SpringBootApplication, and I'd prefer not to mangle with it.
If you want a runnable 'Jar' file, then the jar file must contain the Web server, so you best option is to convert your application to spring boot. Spring boot is able to package an application as a war file, so it can be deployed on a Tomcat, or be launched with java -jar, but it has to be a spring boot app to begin with.
I'm using maven and the embedded tomcat through the tomcat-maven-plugin to run my Spring MVC project. Now I've got a another war file which I also want to run on this tomcat. Is there a way to achieve this? It doesn't seem to work, when I put the war file in the webapps folder of the embedded tomcat.
support of this feature is in snapshot version of the plugin see https://issues.apache.org/jira/browse/MTOMCAT-169