Spring Boot: Embedded servlet container is not working properly - spring-boot

My project is using MDHT(Model Driven Health Tools) Runtime Api Library which is based on Eclipse Modeling Framework(EMF). It works when servers in Spring MVC project. But for some reason the EMF package registry is not getting loaded properly and therefore it cannot deserialize as a Consol CCD document when try to servers in Sprint Boot project.
Code Sample:
Mu2consolPackage.eINSTANCE.unload();
ConsolPackage.eINSTANCE.eClass();
CDAUtil.load(in, result);
Link:
MDHT(https://github.com/mdht/mdht-models)
User Documentation (https://www.projects.openhealthtools.org/sf/wiki/do/viewPage/projects.mdht/wiki/User%20Documentation)
Edit:
After changing to use external tomcat to deploy instead of spring boot embedded servlet container. It works, but still cannot resolve using embedded container.

Related

Deploy spring boot applications

I know spring boot applications can be deployed to production environments as war files. But what is the typical way of deploying spring boot applications? Does it only require a jvm, not a container?
The Spring Boot Project Page states that Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
Means by default, the Spring Boot maven or gradle plugin builds self-contained executable jars, that contain all dependencies and an embedded webserver, e.g. tomcat or jetty. The Spring Boot Getting Started doc gives you an introduction to that. Using this approach you just need a JVM to run your application. But you can also configure it to create war files if this is a better fit to your production environment.
Does it only require a jvm, not a container?
It can run anywhere Java is setup.
Spring Boot's use of embedded containers and why Spring chose to go the container-less route. Many of their main driving forces were ease of use while testing and debugging, and being able to deploy Spring-based Java applications to the cloud, or any other environment.
Rest can be found out in attached image.
Spring boot applications if they are serving web requests do require a container. You can either deploy them as a war inside a container such as tomcat/jetty. Or you can deploy them with embedded container, tomcat.

Can SpringBoot be use for Backend application?

One of the Spring framework advantage is dependency injection. Many had used SpringBoot for providing REST Web Services.
Read up and notice there are Scheduler and CommandLineRunner for SpringBoot, could we using SpringBoot for backend type of application to replace the usual standalone java program while making use of SpringBoot advantage (Dependency Injection)
- Cron Job (Execute and stop running)
- Long Running Process
One of the main thing I am looking into is to use annotation such as Spring Configuration, Spring Data JPA and other technology in backend application.
Of course!
I used spring boot to back CLI projects, DB access projects and more.
Spring boot is very modular. It works by providing auto-configuration based on your maven/gradle imports. If you don't import starter-web/starter-jersey or any other starter that is for the web/rest api, the auto-configuration for this resources won't be triggered and you can basically enjoy all the power of spring boot to support your needs
Definitely,
Spring boot is not a separate framework.It reduces the configuration difficulties when you using spring framework. Spring boot provides a Rapid Application Development using without complex configuration including your dispatcher servlet, XML file for database connectivity and configuration files. You can use spring boot for back-end development. Simply says you can do everything what you does in spring MVC without any complex configuration. If you are using spring boot , You can configure your database details in application.properties file. I am adding one of two links for proper reading,
https://projects.spring.io/spring-boot/ ,
https://dzone.com/articles/why-springboot

Does spring boot needs a WAS (Websphere Application Server)?

In my theory spring boot is capable of running java web application stand-alone. It says it has a own embedded servlet container and can use JNDI itself.
I built a war file before (spring-mvc, security, gradle built), but Spring boot assemble jar file and it runs on any machine which has JVM.
So my question is, if I made a spring boot based web app (contained JSP files & JNDI for looking up datasource), although it has own embedded servlet container and packaged jar file for running standalone, do I still need to package it as WAR file and deploy it in WAS (Websphere Application Server) or servlet containers for any reasons such as performance, stability, scaling-out etc?
WAS is an full blown Java Enterprise Application Server, on the other hand you have Spring that only requires a Servlet Container (Servlets are a part of full JEE).
Servlet Containers are for example: Tomcat, Jetty, but also WAS.
Spring Boot is able to package the complete application TOGETHER with the code of Tomcat in an JAR, so that this jar contains the Servlet Container and your Application.
Do I need a additional WAS for performance, stability, scaling-out etc?
Performance: No - There should be no important performance differerence between Tomcat and WAS when you run a Spring-Application. (Only that Tomcat needs less memory for itsself)
Stability: Tomcat and WAS are both very mature products.
Scaling: You can build a cluster of Tomcats by your own.
The main features of WAS over Tomcat are:
- WAS supports EJB and CDI (Tomcat would need TomEE for this), but Spring will not use it, because it is its one Dependency Injection container
- WAS has more Monitoring features, but this does not matter, because Spring Boot has Actuator
#See Difference between an application server and a servlet container? for more details
Simple answer is No. You do not need any Full blown application servers for any of the reasons that you mentioned (for performance, stability, scaling-out). You can just do fine with tomcat
Edit
Looks like you are using only JNDI feature from the Application server. Do you really need JNDI when you pack your servlet container along with your application ? I don't think so. That days are long gone.
JNDI really shines when you have to move an application between
environments: development to integration to test to production. If you
configure each app server to use the same JNDI name, you can have
different databases in each environment and not have to change your
code. You just pick up the WAR file and drop it in the new
environment.https://stackoverflow.com/a/7760768/6785908
(If you still need JNDI to be used to look up your data source refer: https://stackoverflow.com/a/24944671/6785908).
No, still I do not really see a reason for packaging your application as WAR and deploy it to traditional application server. That being said, if you have some existing infrastructure lying around and you are being forced to deploy to existing WAS (or WebLogic or JBoss any application server for that matter) server, then I rest my case :).

How to set up Spring multi maven module using spring boot

I would like to evolve my Spring application with a better architecture. The technologies I'm using are : spring portfolio ( spring mvc, spring test, spring Web, spring core, spring rest...)
Today I'm using packaging to structure the different layers of my application: models, services, api and of course web where I have my controllers.
I would like to know how can I use the power of spring boot to make a multi module maven architecture with an xml spring configuration for a Web application. I read that spring boot have an embedded tomcat and since I'm using eclipse with a separate tomcat server I would like to deploy my application on it and I think that this can create a problem.
I already found some links on github with this type of projects most of them are not elaboring an architecture of a Web application and use a class for spring configuration with the embedded tomcat that spring boot offers.
Thank you
Ps: sorry for my bad English
What you mean by multi module. If you want to build your jar for multiple environment you can use maven profile for it. Spring boot is nothing but a spring project which ease the configurations for you.
Regarding deployment to your own server, you have to convert the jar to war. Read "What about the Java EE Application Server" section of below link.
https://spring.io/blog/2014/03/07/deploying-spring-boot-applications

Can Spring Boot + Gradle generate a war file compatible with Servlet 2.4?

I've been reading about using Spring Boot and Gradle to quickly build RESTful services: https://spring.io/guides/gs/rest-service/. I'd like to give it a try but I need to build a war that's compatible with servlet 2.4 (I know.. life in the 1970's).
The error I get when attempting to deploy the war generated by following the guide above to Sun App Server 8.1 is:
Unknown deployable object type specified: "Cannot determine the J2EE
component type"
The generated war has no web.xml and there may be other expected artifacts.
Configuring a spring-boot application using web.xml seems to suggest that a web.xml can be packaged with a Spring Boot application but doesn't explain how.
Is Spring Boot compatible with older servlet specs? How can Spring Boot and Gradle be used to generate a war that works on older web containers?
Thanks.
The answer to the question you linked to didn't actually go as far as saying that you could easily create a fully-leaded Boot application with Servlet 2.4. I consider that quite a hard, but probably achievable, target if you are prepared to do some legwork, and accept some compromises. You might find this stuff useful: https://github.com/scratches/spring-boot-legacy (I managed to use it to push an app to GAE). But there are some limits to what can be supported for such old technology, and we aren't officially supporting anything other than Servlet 3.0.1 right now.

Resources