Spring boot basic - java

Just started exploring spring boot and trying to understand.....
In a normal project scenario, we create multiple projects / modules depending on functionality. Ultimately, package all different jars , wars in .ear and deploy it.
With spring boot, new project are deployed on a separate of instances of tomcat.
But if all these projects are related, it will need reconciliation of proprty files and any other resources differently utilized, before you create .ear.
While I understand the advantages of spring boot while development, is there any thought on how to make this process better when using spring boot?

Modern cloud architectures are moving away from using property files. Your Ops or DevOps teams should appreciate if your app would accept configurations via system properties. Spring Boot is perfectly suited for that.
Older fashioned orchestrators would replace placeholders in your properties files during deployment phase.

Related

Spring MVC or Spring Boot for wildfly deployment

I am converting Java web project into Spring Project. (10 JSP and 5 controllers connecting to DB)
We are using Wildfly server for deployment.
Is there any use of creating Spring Boot project (though i have facilities like actuators, starters etc.)
or
Is it fine to create Spring MVC Project and deploy the war in Wildfly as i am not using any container here and spring boot project will be an overhead? Basically i am finding why should i use spring boot here?
it depends.
Spring boot is just SpringMVC + Tomcat in one JAR (very simplified definition, I know).
If you have an existing and working Wildfly Server, use it. Compile your web app as WAR an deploy it. You will have also better configuraiton, server update and server bugfixing possibilities. At least that was in my case, as my team mates had a lot of experience with Wildfly.
We are using SpringBoot for small pure REST (micro)services (without HTML, JSP), since they are fast to implement and to deploy (just run a jar file). All of these applications have their own Tomcat server - with own PORT. If you want a new Tomcat version you have to recompile your application. This could be a disadvantage (but not realy).

Spring Boot library usage in plain Java project

i´m currently working on a Spring Boot jar library for reuseable components like
ldap
email
messaging with apache kafka
rest api usage
Aim:
Every Java "user/coder" of our company should be able to "put" this jar in ones project (by maven or whatever) and use the reusable components instead of coding all things by hand over and over again.
Building microservices for that issue over REST is not an alternative to us.
My question is:
Can i reuse this Spring Boot jar library in any plain Java projects?
Beeing fond, can i "put" this jar library into a Java project and wire my Spring Boot services from that library in my "non Spring Boot" vanilla Java project?
Notice / Edited:
I have used Spring Boot as project template (spring-boot-starter-parent).
I configure my templates like the LdapTemplate by hand and don´t let Spring Boot do the magic.
Edit
As far as the reuse in Spring Boot/Spring projects is concerned, everything is fine. I´ve done that already.
My aim with that library may be that every Java "user" can use this library, like so:
final SuperCoolLibary scl = new SuperCoolLibrary();
final boolean exists = scl.searchForLdapUser("tlang");
So another question maybe:
Would it be better do switch this library to maybe the new Java Jigsaw module infrastructure?
Write your own Spring-Boot-Auto-Starter. A guide can be found under: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html
This way your library can be used in every spring boot project by just adding it as dependency (which means the jar must be in your classpath).
If your Java Application does not use the SpringContext the services cannot be "wired" by spring into your plain vanilla java application.

How to deploy spring boot web application with configurable properties

After researching i learned that the common way to deploy spring boot web applications is as a war file.However,i have a project i made for a company,now i need to send them the project to try it out and they need to be able to configure the application.properties or to be specific the database location and credentials.so my question is do i need to deploy the project in a different way or is there a way to make the war file application properties modifiable later ?
Did you consider Spring Cloud Config Server
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html.
This is the most elegant way to configure and externalize your properties. If not I would strongly suggest incorporating that component. Plug the config server with your spring boot app without much coding and your application will be much more manageable and extensible.
Spring Boot applications are actually typically packaged as Uber jars with Tomcat embedded. You can accomplish this using spring-boot maven plugin or a similar gradle plugin if need be.
Once in this state the jar can be started normally and you can override configuration properties when invoking it.
java $JAVA_OPTS -Dspring.service.name=my-service -jar /my-service.jar
EDIT: This is not the only way you can solve this problem, and #piy26's answer is an excellent solution for injecting external configuration into an enterprise ready spring boot application. However for the case that your are describing you would need the company to set up there own configuration server, and whats more they will still have to override the configuration server location property so the application will pull properties from their config-server. For your example it seems you need the simplest way to override application properties within the jar.

will creating multiple spring projects that will go into one EAR create multiple spring containers?

I want to be able to create multiple spring projects in eclipse that will work together that will be created as one EAR. For example, a Spring JMS project, a Spring-WS project, etc. Since these technically can be treated as a sepearte project, will this create multiple spring containers? I would like to have one spring container that will be shared, especially for common configurations such as the data source bean.

What do I need to download to start developing apps using the Spring framework?

I need to start developing applications using the Spring framework, and am wondering what tools I need to download to have me up and running.
On the SpringSource website I am seeing all these applications to download and I am wondering, do I really need all this? And what versions should I use, especially for Spring Framework?
Spring Framework
SpringSource dm Server Samples
Spring Security
Spring Web Flow
Spring Web Services
Spring Dynamic Modules
Spring Integration
Spring Batch
Spring.NET
Spring JavaConfig
Spring LDAP
Spring Extensions
Spring IDE
Spring BlazeDS Integration
SpringSource Bundlor
Spring ROO
What other applications do I need to download (eg. Struts, Glassfish, Apache, etc.)?
This depends on what you want to use Spring for. Typically that's Web applications. If so you only need two things:
Spring framework (with minimal dependencies); and
A servlet container (eg Tomcat) or a full-blown application server (eg Glassfish, JBoss).
Everything else is optional. I believe the only required dependency is Apache Commons logging. Depending on what features you use, you may well need more.
If so, here is a [tutorial][1] that creates a barebones Spring MVC project. There are countless others around for that and other topics.
It's entirely possible to use Spring in, say, a Swing application in which case you obviously don't need a servlet container.
All you need from SpringSource is the Spring Framework.
Spring 3.0 is on the way, but for now, use 2.5.6.SEC01, the current production release.
You can get started with a simple servlet container (ie: Tomcat) rather than a full blown application server (eg: JBoss, Glassfish).
The Spring Framework comes bundled with jars for web development - ie: spring-web and spring-webmvc.
See #117535 for a simple example of using Spring MVC.
It mainly dependent on what you need Spring for. Each and every piece of Spring can, actually, be used in separation from the rest. You may use it only for IOC, in this case you don't need, for example, MVC and Servlets, etc...
The easiest way to start is to dowload the main package from http://www.springsource.com/download/community?project=Spring%20Framework
You can use Spring from any IDE
The best way is to use Maven with your project. Basically all you have to do is edit your pom.xml file and tell it that you want to use Spring. Then when you compile your code, Maven will go out and automatically download the Spring libraries you need from their public repository.
Here's an example:
http://pookey.co.uk/blog/archives/63-Getting-started-with-Maven-and-Spring.html

Categories