Using Cesium.js inside Spring MVC project - java

I have a project which is built on top of Spring MVC (not Spring boot). I used the Spring Tool Suit(STS). I want to add the functionalities of Cesium.js project to my Spring Project but the problem is Cesium is a Node.JS application.
I do not know how should I reference the Cesium project inside my Spring MVC project.

I read the documentation but it was not clear what to do.Basically it says you have to move the root folder to your project and then use it but with Spring MVC its a little bit tricky.
I moved the resource folders to a folder under my resources in Spring MVC project and kept the index of cesium in my views folder, made a route to it in my controller then I changed the links in the index according to spring links and also changed the suffix to jsp instead of html and it all worked out.

Related

Adding Spring boot to existing JSP project

We have an existing JSP project that serves a website and a REST interface. However its an old project (started in 2013) and now it does not scale well with new requirements. We would like to add Spring REST interface under the same project (sharing same tomcat and sessions) until we we migrate completely and drop the old REST interface (and the website) entirely.
Current project structure is:
Root/
website/
rest/
WEB-INF/
web.xml
classes/
META-INF/
context.xml
Current rest interface is accessible via /rest/xyz.jsp
Now we would like to use Spring and migrate rest/* such that they will be accessible via /api/*
How do I integrate Spring boot into this project? what set of configuration do I need to make?
Spring boot docs and internet weren't helpful.

Is it possible to nest a Spring Boot application inside another Spring Boot application?

I have a Spring Boot RESTful microservice that a customer would like to nest inside their Spring Boot application.
Could someone tell me whether this is possible?
I was hoping this would be as simple as adding a dependency on my application in the customers maven pom file and then excluding the tomcat dependency since the customer already uses the embedded tomcat.
Thanks,
Ben
Since they already use Spring Boot to start their app, you can simply mark all Spring Boot dependencies as provided in your Maven POM, this would exclude it from the JAR as well as embedded Tomcat and all related dependencies. Also make sure you don't build your JAR as a Spring Boot executable (should be the default if you're not using the spring-boot-maven-plugin).
On the customer side, they would need to include your JAR as a dependency, and possibly add a scanBasePackages property to their #SpringBootApplication, to auto-discover your application classes, if they don't reside in a package under the one that #springBootApplication is on. Also, they'll need to be mindful of any URI collisions between your app and theirs, as the two will be sharing the same environment.

spring boot parent for jar file

I want to create a jar file that I can add to a classpath and will basically "plug-in" to an existing spring boot application. I need it to be able to have annotations of Component, ConfigurationProperties, and all the fun things that spring boot gives you, but I want it "thin" and it will be a jar file used as part of a full spring boot web application.
I need the jar file to be externally configurable. Property files will be different for different deployments. So having a working #Configuration annotation is critical.
I look at spring-boot-starter-parent, and that has jetty, tomcat, hibernate stuff and is a huge jar file. I don't want that.
Is there a "thin" parent?
Is spring boot simply not what I want here? And I should just use a regular spring project and set my "Main" spring boot web app to do component scans to configure the jar file?
It sounds like you are trying to define your own Spring Boot Starter. That's the real power that Spring Boot gives you, the ability to include a dependency and have it auto-configure itself.
By packaging your jar the right way, Spring Boot will detect that there are configurations, components, and property files automatically. I've used this in the past for the case where I want all of my applications to log a specific way, or enforce a certain format for my REST endpoints.
The documentation gives a very thorough overview of the steps you'll need to take. But essentially, you are going to package your jar like any other (with your #Bean, #Component, #Service, and #Configuration classes in it), and provide a property file pointing to the configurations:
// Example spring.factories file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.mycorp.libx.autoconfigure.LibXAutoConfiguration,\
com.mycorp.libx.autoconfigure.LibXWebAutoConfiguration
Also check out the set of #ConditionalOn... annotations, they can really help with controlling what beans become active based on properties being defined, profiles being active, or dependencies being loaded.

Properly (and easily ?) initiate a Spring MVC Project

What's the best method to initiate a new Spring Project ?
Initiating Spring project is a lot of pain with various xml and db configuration.
Is there an "official" repository with complete sample project, as MVC with db access and so ?
Spring Boot may also be the solution, but some point still not clear to me :
How to add external components (such as Quartz) without creating some xml config ? (No such xml in Boot apparently)
Is a Spring Boot builded app is production-proof ?
As writen in the comments http://start.spring.io/ is the best way to start Spring boot project(STS has integration for it).
If you want to use something that is not supported by Spring Boot you can init spring beans the same way you do it in xml, just use java configuration. See this for example: http://www.tutorialspoint.com/spring/spring_java_based_configuration.htm
Also useing xml is still available. You can add #ImportResource on your Configuration class
#EnableAutoConfiguration
#Configuration
#ImportResource({"classpath*:applicationContext.xml"})

Is it possible to share the same MVC between external Jars and a War in Servlet 3.0 environment?

I understand that Servlet 3.0's enhancements have made it possible to display a .jsp from a .jar, based on Can I serve JSPs from inside a JAR in lib, or is there a workaround?
However, I don't seem to be able to connect my View (jsp in jar WEB-INF/lib Tomcat 7 and classic spring MVC context configuration in a War) with the Model and the Controller of my Web App.
Is there a good way to share the dispatcher Servlet, or perhaps create a CustomViewResolver which could scan .jsps included in external JARs, and actually plug my jar into a unique spring context?
With JSP you have the problem of compilation.
So you at least need to precompile them, to have them included. Then it should be possible, since after compilation a JSP is basically a Servlet.
If you would use another view technology like Velocity, Freemarker or JSF based on Facelets, you can very easily use a classpath based ViewResolver.

Categories