Is there any way to add dependencies to existing spring project using Spring CLI (for instance via shell)?
I tried to looked for on this website
docs.spring.io.
But I couldn't find working way of adding dependency like Spring Web or Spring Data JPA to existing spring project.
If you are using STS or Eclipse for your development then you can easily add dependencies using CLI. You need to press the Ctrl+Space Bar in your pom.xml. It will show you the option with Edit starters as shown below, then click on it it will open your CLI interface
Ctrl+Space Bar
You can use pom.xml to add dependencies to your existing spring project whether you created your project by using Spring CLI or any other way.
Go to Maven Repository: https://mvnrepository.com/
Search for your required dependencies
Copy the dependency for maven and paste it in your pom.xml
To add a dependancy from Spring CLI, you can use the following command:
spring init -a <name_of_your_artifact> --dependencies=web,data-jpa <my_project>
where:
<name_of_your_artifact>: the artifact Id for the project.
and
<my_project>: name of the file where the .zip of spring initilizer will be extractred.
Related
i'm trying to create a spring MVC project using intellij Ultimate 2020 but i don't have it available in my menu :
Is there a way to get the Spring option ? i already checked that the Spring plugins are all enabled .
The Spring Initializr can generate a Spring Boot project structure for you. It will give you a basic project structure and either a Maven or a Gradle build specification to build your code with.
You can use Spring Initializer to generate a spring project. It will provide you with all the dependencies required for SpringMVC project
Go to https://start.spring.io/.
Just specify the dependencies.
Download the generated project.
Open the project with IntelliJ.
Resolve the dependencies by specifying the unmet ones in pom.xml if found any.
Good to go!
I don't know are u new in spring, but if u are, here some advice to start in idea.
First of all, visit https://start.spring.io/
First 5 steps of instruction matches with numbers on this picture
https://i.stack.imgur.com/T6NW1.png
Choose dependencies u need, for example start with spring web(mvc)
Choose your language, u need java
Choose which dependency manager u will use, for example maven
Choose spring boot version, for example 2.3.3
Give a proper name to your future project, it's not necessary
Press GENERATE
Unzip downloaded file
IntelliJ Idea -> Open or Import - > select unziped folder
Every time I start new Spring Boot project using Spring Tool Suite Spring Starter Project I can add dependencies using GUI like on the screenshot below.
It's very convenient to choose dependencies in GUI. But sometimes I forget to add some dependencies and have to add them to pom.xml manually.
Is it possible to add new dependencies using GUI the same way like during Spring Starter Project configuration after project creation?
Yes, you can. Right click on the pom of the generated project and choose Spring -> Edit Starters from the context-menu. It opens up the same dialog and lets you add additional dependencies.
You just need to take care of the correct Spring Boot version yourself, it isn't set automatically to the version that you chose when you created the project. It doesn't cause any huge trouble if you choose the wrong version, but spring starter modules might show up that aren't compatible with your project.
I understand the concept of Spring boot, but I am looking for the logic how it is implemented and where it is maintaining the configuration. When we add any Starter-pom immediately it is giving the dependency and the configuration needed for it. How it automated that feature and where is that automating code in the spring boot?
Thanks in advance
The configuration classes for Spring Boot are in the module spring-boot-autoconfigure. A starter POM has a dependency on that (through the general spring-boot-starter module) and the required 3rd party libraries, and then the autoconfiguration for that library is activated.
The SpringBoot project has been put there so to be more productive & build production ready app in no time. SpringBoot project referes many starter projects like spring-boot-starter-jdbc, spring-boot-starter-logging, etc. All these starter libraries are like maven sub module projects and they add a set of libraries to respective project in turn. Like the spring-boot-starter-jdbc library adds these libraries -> spring-jdbc,spring-tx,tomcat-jdbc.
Now for the configuration part, spring boot has maintained another library called spring-boot-autoconfigure which auto configures all needed configs depending on the libraries present on your pom and the initial set of config annotation been used on the app. For Eg. if it sees ojdbc jar present in your pom then it will autoconfigure oracle datasource to your project
From my bare understanding, this feature are not provided by Spring Boot. It is the power of Maven. Maven allow you to declare dependencies, and the dependencies themselves, PLUS the transitive dependencies will be retrieved.
The starter POMs are simply normal Maven POM-type artifact which declared essential dependencies, and hence, when you include in your own POM, related dependencies will be downloaded.
You may get some more understanding on Maven from Maven Site or Maven Guide by Sonatype
I want to use GAE with Spring MVC
so, I found this following site.
here
but This site's example seems to manually add jar files.
I think it is inefficient.
In eclipse, Is there another way like adding dependency on pom.xml in spring MVC project?
I would suggest you to git clone the guestbook-spring project (it's adding Spring MVC to the GAE guestbook example) and continue from there.
We have builded our webapp app based on this, and it's great.
P.S. Also, it got tests for the controller included. It's good to have it as inspiration for testing you future app (as a developing practice).
Yes, if you have created a maven project, then it is much easier to add dependencies using pom.xml.
You can edit directly, or use eclipse maven pom manager to add dependencies directly, or from a repository.
The link you gave does not create a maven project, but you can modify the instructions so it does.
You can create maven project instead of Web Application at the start, then add Spring dependencies and continue adding dependencies from there.
You could use gae archetype to create your project firstly, and then add spring components to pom.xml:
mvn archetype:generate -Dappengine-version=1.9.14 -Dapplication-id=your-app-id -Dfilter=com.google.appengine.archetypes
where -Dappengine-version is set to the most recent App Engine Java SDK version, and application-id is set to the Developer console application ID used for your app.
I found simple way.
1.First, Create Spring MVC Project, and add dependency and plugin in pom.xml
1.1 add gae dependency
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.14</version>
</dependency>
1.2 add gae plugin
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.14</version>
</plugin>
In WEB-INF, create appengine-web.xml and logging.properties
then, you can run it on server
Create a new Web Application project as it is shown, after that right click project -> Configure -> Convert to maven project.
I am using eclipse kepler edition. I install eclipse sts plugin for kepler. But when I want to create a spring-roo project in the dialog it say that there is no roo installation configured. then I try to add dependency from spring site
<dependency>
<groupId>org.springframework.roo</groupId>
<artifactId>spring-roo</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
to my project pom file. but when i run command mvn clean package -U it say no dependency information available. I was looking for it on mvnrepository i cant find it and on findjar.com. It seems the spring foo does not exist on repo.maven.apache.org/maven2. I have no problem in getting other dependecy and every thing work fine except spring roo.
You need to configure the following repository to access Spring Roo artifacts:
http://spring-roo-repository.springsource.org/release