Custom Spring starter vs standard Jar - spring

Why should we build our own custom starters when we could just use a standard jar (ie. putting all your common codes and component into a single project, build the jar and use it in another SpringApplication)?

Related

why are the github projects of spring-boot-starter projects empty?

On looking at the spring-boot-starter-web, spring-boot-starter-security projects on github, i find them to be empty with just a build.gradle file present there.
I hope this is as expected, but this leads me to understand where the actual source code can be found. And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
I hope this is as expected
This is as expected. Spring Boot's starter modules exist purely to being multiple dependencies together into a convenient "package". For example, if you want to write a Servlet-based web application using Spring MVC and Tomcat, a single dependency on spring-boot-starter-web provides all of the dependencies that you need. You can learn a bit more about the starters in the reference documentation.
Where the actual source code can be found
The majority of the code can be found in spring-boot-autoconfigure. For more production-focused features, you'll also find some code in spring-boot-actuator-autoconfigure. The code in these two modules is activated automatically when the dependencies that it requires are on the classpath. You can learn more about this conditional activation and auto-configuration in the reference documentation.
And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
Spring Boot is built with Gradle which, unlike Maven, completely separates the configuration needed by the build system to build the project and the information needed by a build system to consume the project. The build.gradle files provide all of the information that Gradle needs to build the project. As part of this, it generates Gradle module metadata files and Maven pom.xml files that contain all of the information needed to consume the project with Gradle and Maven respectively. These generated files are then published to Maven Central alongside the jar files, source code, etc.

Spring framework library

Can I make a library with Spring framework, and then include that library in an application that uses the Spring framework?
Yes you can make a library that uses Spring, and then include a dependency on that jar in another application created with Spring. You will want a build tool that handles dependencies, like Maven or Gradle, and probably a repository manager like Nexus or Artifactory to store artifacts that you create.
You have to make sure that the jar gets included in the component scan performed by the hosting application. See the Spring reference documentation on Importing configurations.
If the library has its own Configuration, importing the Confuguration gets it included in the component scan.
Alternatively create a marker interface in your library like this:
#ComponentScan
public interface MyLibrary {}
then in the including application have a Configuration class annotated with
#ComponentScan(basePackageClasses= { MyLibrary.class })
and the including application will scan all Components in the package hierarchy starting from the package of the marker interface.
Spring is open source so you can contribute to it. Refer to https://github.com/spring-projects/spring-framework/blob/master/CONTRIBUTING.md for more details.
Yes, any Java based applicaiton (like spring framework) can be packaged as a JAR file and published to a repository (or store it locally to start simple)
This Jar file can be included as a dependency in another Java based application (like spring framework)
To add dependencies you can either use Maven or place it in a directory and add it to local classpath for the next application to use the library.
Your library becomes a reusable library (usually a JAR file) for all other java based applications

Spring Boot - package application classes as a jar in BOOT-INF/lib

I am using Spring Boot 1.4.1 with Gradle 3.1. The module which has the Spring Boot plugin applied creates its own jar with the jar task, and also has the 'fat' jar created with bootRepackage. However, the classes from that module are in BOOT-INF/classes, but I would like them to be in a separate jar in BOOT-INF/lib. How to do this?
EDIT: I know I can move the code to a separate module, but for various reasons I can't make such a split (unless there is no other way). I am looking for a single-module solution, if one exists.
You'll need to set up a multi-project build and move all of your Jersey-related classes into a separate project. You can then depend upon this new project in your Spring Boot project using a project dependency. For example:
dependencies {
compile project(':jersey-endpoints')
}

What is a general way to use a Spring project inside another?

I have a Spring project which is a regular jar file. It uses JPA and Spring Data.
I'd like to use it in another Spring project, which is a war running in Tomcat. It also uses JPA and Spring Data.
I have installed the jar into the local maven repository, and have declared it as a dependency in the parent project.
What do I need to do to make them work together correctly?
Are there naming conventions for the various context, properties, and persistence files?
Do I need to import the library configuration files in the "parent" configuration files?
I am getting the following error when trying to run the parent:
IllegalArgumentException: Not an managed type: class [some domain class in the parent project]
Use Maven Modules. Reference here:
http://books.sonatype.com/mvnex-book/reference/multimodule.html

Pulling out domain classes from a Spring Roo project

We need to be able to pull out domain classes (i.e. entities) from a Spring Roo project in order to reuse them for a Spring Batch project.
Is this possible?
Bearing in mind that we rely on Maven as our build and dependency management tool, and that our Roo project is already created, can we switch to a multi-module architecture?
If so how?
I don't think there is a roo command for converting a single module maven project to a multi module project.
One option would be to use roo to create a separate persistence module in your current project and manually migrate your entities and configuration over.

Resources