What should I do if I want to add module in a started spring boot program? - spring-boot

I can initialize a spring boot project with initializr in idea, but what should i do if i want to add a new module. For example: I select web moduel first. And letter I want to add mybatis in the project.

You can add new module to your project in IntelliJ by
right-clicking your project -> New-> Module
You can follow this link
https://www.jetbrains.com/help/idea/creating-and-managing-modules.html#multimodule-projects
This will create a new module and also add your module to the settings.gradle file making it a multi module project

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)

Converting existing project to Spring boot project in InelliJ

I have an existing project. I need to make it a Spring boot based project and I am using IntelliJ CE.
What would be correct procedure for doing it?
Edit:
Project has no initial structure. It is a totally empty project. So no existing modules etc.
Spring Boot is an Ultimate feature, so first you would need to try/buy the IntelliJ IDEA Ultimate.
From there, you can add Spring support to existing project modules or use the Spring Initializr wizard to select the necessary configuration when creating a new project or module.
In your maven pom.xml or build.gradle file, I would add the spring boot starter dependency:
spring-boot-starter (the group id is org.springframework.boot)
If the application is a web application, I would also add the web starter spring-boot-starter-web also with the same group id (org.springframework.boot)
For convenient features, applying the spring boot plugin would help in creating a runnable jar with all required dependencies bundled called a fat jar.
A great tool I use is the spring boot project generator. It allows you to configure the modules you want and create a project template.
Spring Boot requires IntelliJ IDEA Ultimate. If you want to use IntelliJ CE, please create a project using Spring Initilizer then import the same to your IntelliJ CE (File -> Open -> Choose the project root folder). After you import the project, wait for some time so that IntelliJ can download the dependency and build your project. You can check from (Build -> Build your project). Then find the main class of spring boot and run it using the green play button

When spring applications with gradle multi-module run on intellij's dashboard, it can't load property sources

I setup spring boot applications project with gradle multi module project. Each module is just spring boot application. To run all applications, i have to refresh all module using refresh gradle project on root project. On the other hand, If i refresh a specific gradle module, other applications which also are submodule cannot load property source.
For a detailed explanation, i want to present sample application:
https://github.com/samplesrepo/sample-demonstrating-boot-cannot-load-propertysource-in-multi-module
And i uploaded a video demonstrating this problem in youtube:
(https://www.youtube.com/watch?v=5kGu6MhHfmY)

Spring Boot multi module WAR Generation

I have made a maven Spring boot (REST) Project that has 3 (maven) sub modules (i. api ii. implementation and iii. service modules).
The main method (#SpringBootApplication) is in the root of the project. The REST web service works fine from IDE but maven does not allow me to package this project as war and deploy to external tomcat.
To solve this I added a new module and added dependencies of other modules within this and packaged this as war (by adding maven-war-plugin). But when deployed on server; the webservice does not get hit.
Structure-
Service Project
main()(This is within root project)
api module
service module
implementation module
Newly added module (that has above 3 modules injected as dependency and the plugin that let me package this as a war)
Expecting a war that has all these submodules that can be deployed on external Tomcat 9 server.
How to achieve this?
Please Note - I have added spring-boot-maven-plugin
to repackage in the root project, but it is not working.
Adding parent to this newly added module fixed the issue and I was able to make a working jar!

Adding JPA support to an existing Maven project in IntelliJ

I've been working on a project in IntelliJ for a while now using Maven (My god, maven is cool!). For the persistence I wanted to use JPA.
The issue is that I'm not sure how I can enable JPA support for my existing project, following this guide didn't work since my code still can't use tags such as #Entity.
It looks like IntelliJ is adding a new package (?) for JPA that my existing code can't access. Here's my package structure:
My existing code is in the src directory, while IntelliJ created the JPA directory for JPA.
Is there something I can do to add JPA to the existing code, or should I move my existing code to the JPA directory? I would like to keep using Maven.
Thanks!
while IntelliJ created the JPA directory for JPA.
it's weird. IDEA sholdn't create new source module if you just try to add JPA support to existing code.
Try to add JPA facet to your existing module via Project Settings
File--> Project Structure --> Facets --> click on + --> Select JPA

Resources