Is bad practice to have spring boot starter project for starter project? - spring

Spring boot starter project provides extensive set of functionalities auto configured. But for our application we want to have only a subset of functionality. May be only one feature out of the spring boot starter project. So is it advised to have custom starter project on top of spring boot provided starter project to mask some of the features or write new starter project directly from lower level libraries?

Spring boot starter project provides extensive set of functionalities
auto configured
There are two separate concerns you are talking about.
I think the auto configured part is something which is Spring boot's opinionated way of configuring. As an example if in classpath it finds a in-memory database library ( like H2) it automatically creates a datasource (pointing to embedded in-memory database) which is available for autowiring without you writing the configuration in a Java config class. Of course you can create you own datasource of choice by including appropriate driver jar for that database. Similarly lots of other configurations are done by default by classpath scanning and availability of certain jars and classes.
The second part - is more of a dependency issue in general. Say you want to use web mvc part in Spring boot. This will require a consistent set of dependencies and transitive dependencies as well. Rather than finding and declaring the dependency in your build tool of choice ( maven, gradle etc) it has created the concept of starter projects where you simply mention the parent and all the right dependencies would be pulled on. This gives a great way to correctly lock your dependencies. However if you want to include any different version than what is provided by boot starter ( provided there is no compatibility issues with those different versions) you can still add explicitly in your build tool. For e.g., maven will by default include the highest version of a particular dependency among all available via transitive dependencies when it resolves dependency for an artifact.

Related

How do big bundled open source projects like Spring Boot ensure compatibility between modules?

Spring Boot contains loads of dependencies: Spring Framework, Spring Data, etc. How do the Spring maintainers accomplish releasing everything while different teams work on different Spring projects?
We have a similar situation, we have 4-5 teams each making different libraries which are used by other teams. We prefer to be able to allow teams to release independently but this is a huge undertaking to ensure binary compatibility of interface and behaviour.
Each release of Spring Boot provides a curated list of dependencies it supports. In practice, you do not need to provide a version for any of these dependencies in your build configuration as Spring Boot is managing that for you. When you upgrade Spring Boot itself, these dependencies will be upgraded as well in a consistent way.
The curated list contains all the spring modules that you can use with Spring Boot as well as a refined list of third party libraries. The list is available as a standard Bills of Materials (spring-boot-dependencies) and additional dedicated support for Maven and Gradle are available as well.
URL: https://docs.spring.io/spring-boot/docs/1.3.8.RELEASE/reference/html/using-boot-build-systems.html

Is there any particular reason why Spring boot starters using Maven? Is it straightforward to use gradle for custom starter with artifactory?

I am trying to balance time and avoid stepping on mines, on one side we have artifactory which is gradle based and need corresponding work to integrate with maven/gradle plugin(preferably with latter as most of our projects are gradle based) on another side all spring boot default starters in source are pom.xml + I only found single gradle custom repo:
https://github.com/web3j/web3j-spring-boot-starter in several pages of search results which uses gradle. But the build file looks pretty convoluted and includes a lot of maven parts.
I am happy to invest time into gradle if someone gives a green light with example/guide/share experience. Thanks. Just to understand if there is some particular reason why the situation is like that or I am afraid of ghosts?
A Spring Boot starter is a jar file containing some compiled classes and, typically, a META-INF/spring.factories file that lists some auto-configuration classes. As such, they can be built equally well with Maven or Gradle. Spring Boot's own starters are built with Maven purely because that's the build system that the whole project uses. If we were starting again from scratch now, we'd probably chose Gradle over Maven.
Some of the third-party starters listed here are build with Gradle, for example:
azure-application-insights-spring-boot-starter
charon-spring-boot-starter
session-couchbase-spring-boot-starter

Spring Boot: starter modules - do i need to keep them?

I am starting yet another project based on spring boot.
For start it's pretty obvious and easy to go with spring-boot-starter dependencies. But for example I have projects which already live for 2 years and it becomes more challenging and time consuming to upgrade versions of those modules. Mostly because lot's of things auto-confugured under the hood, and there is only hidden knowledge to control them.
What would be the best practice to plan the new project for long term support and be able without any problems upgrade spring boot versions?
Are starter modules really just for start? After some time they should be fully replaced with pure modules from Spring framework?
The intention of Spring Starter modules is not necessarily intended to be aimed at being replaced by manually defining your dependencies. In fact, it's more the opposite, as the set of dependencies defined in starters are tested to work as expected as it provides an opinionated set.
The pattern laid out by Spring Boot is two fold, autoconfigure modules and starter modules:
Autoconfigure modules that generally do not, unless necessary, require dependencies downstream. Autoconfigure modules will compile against one or many modules, and then enable configurations within your application context based on rules generally governed by what libraries and components are available at context initialization. This is useful as it provides reasonable baseline configurations that can be used in a variety of scenarios, without enforcing what particular libraries/vendors downstream consumers must use. However, because they are intended to be used in a variety of scenarios, it is incumbent upon you as the consumer to ensure you have a valid context.
Starter modules are complimentary to autoconfigure modules. They provide an opinionated set of dependencies downstream, along with autoconfigure dependencies, to allow consumers to get started. Generally, but not necessarily, starter modules themselves are fairly empty and often do not contain any classes, as their main purpose is to just provide a POM that can be used for transitive dependencies.
Although your query is not about developing custom auto-configuration, the Spring Boot documentation regarding developing your own auto-configuration does a good job explaining the pattern.
Traditionally when we develop a Spring application, we need to include all the required dependencies (spring or other framework jar) by ourself. Starter is intended to minimize such configuration . It does not have any codes or logic inside . You can think that it is just a configuration setting which pre-defines some dependencies. Including a starter will automatically include all of the dependencies defined by this starter to your project thanks to the build system (e.g Maven) 's "transitive dependencies" features.
So you can see that starter provides one of the SpringBoot philosophy, which enable developer to create a Spring app that can "just run" quickly without much configuration , it definitely will not be replaced by the Spring.

How to obfuscate spring boot war file?

I have tried ProGuard, YGuard tools.
These tools are able to obfuscate the code, but at runtime Spring IOC fails. The obfuscation renames all the packages and classes, thus bean injection does not work at runtime. Am using spring boot 1.5.7 and Maven.
DashO has support for Spring (i.e. the Wizard will automatically identify and configure Spring beans) and we published an article earlier this year about how to use DashO with a Spring Boot app (you have to extract BOOT-INF/classes manually, and configure the entry point manually).
You can download a trial for free, and have full access to our technical support if you have trouble getting it working.
Full disclosure: I work for the company that makes DashO.

adding spring-data-rest ontop of spring-data-jpa

i created a maven project, and added all dependencies i need.
i have some repositories using the spring-data-jpa, and i added some integration tests.
now i need to add ontop of it spring-data-rest, if i understand it is based on springmvc.
but all examples i found, i need to add spring boot to start the app.
i noticed also all new spring projects use spring boot.
this means that i have to learn and use it for my projects?
how can i use spring-data-jpa+spring-data-jpa with an existing servlet3 project
The reason all examples are written using Boot is that Boot is indeed the way you should start a new Spring project these days. It free's from a lot of the tedious work of setting up the infrastructure, finding dependencies in the right version etc.
To use Spring Data REST without Boot, simply add the necessary dependencies to your project. The easiest way to do this is to use the Spring Data Release Train BOM (which will help you pulling in the correct matching versions) along side the version-less dependency declarations for Spring Data REST WebMVC and - in your case - Spring Data JPA.
Then go ahead and either register RepositoryRestMvcConvfiguration as Spring bean (either through XML configuration or JavaConfig).
All of this is also documented in the reference documentation.

Resources