Pulling out domain classes from a Spring Roo project - maven

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.

Related

How to add code template which will be available to be added later to my later spring boot projects readily?

i want to create a setup in which i have template code(s) which when starting a new spring boot project can be easily added into the new project.
I tried finding stuff on net which mostly showed adding a custom service or a dependency in the project.
You can create a Spring Boot project that contains nested maven projects is called the multi-module project. this approach give you option to add or remove module (addon project or template)

Can we use Springboot with multimodule for microservices

As Springboot multimodule produces single fat jar will that be good idea to use spring boot multimodule project for microservices
Yes, Actually it is a very good idea to use the multimodule project.
Below are some advantages of that:
Gives clarity about the code and project module
Decouples the layer.
Easy to modify/add the module. Suppose your persistence module is already implemented with Couchbase and now you wanted to switch to Mongo DB then you just need to change the persistence module(dependency, code, configuration) not other parts of a project.
Easy to maintain.
No, I believe. Actually, it is bad design to generate single fat jar for multimodule project in Spring Boot. Suppose, we have multimodule project having 3 sub-modules for different microservices. Then each module will have its individual pom right? that we need to refer in main project's pom as module. Now, assume anyhow we are able to define packaging in main module pom as single fat jar for all the sub-modules. Then, you are not following the microservices architecture guidlines. It will be a kind of monolithic architecture, because all your services are there in a single unit (a jar). Although it would be easy to maintain, but difficuilt to configure through Jenkins pipelines. I mean you have to customize your Jenkins pipelines.
You may refer following url for more details : https://thebasictechinfo.com/spring-boot/spring-boot-microservices-architecture-spring-cloud-netflix-oss

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

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.

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

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

Resources