I'm having some issues with using the Spring framework in Intellij. My question will be in reference to this post:
Intellij idea - Spring Bean Configuration File
"Enable Spring plugin in your project and check Spring plugins (Spring Support, Spring MVC, etc)": There is no option to do this
when I view the available plugins in my Intellij
"IntelliJ has a built in plugin for Spring. Go to File > new Project and create your spring project": There is also no available option
for me to create a new Spring project
My primary goal is to create a bean but obviously that isn't an option without the Spring framework working. Can someone walk me through how to get it set up?
Related
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.
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.
today I downloaded the last STS version (3.8.4.RELEASE) and I have some doubts because it seems to me that something is changed.
I have to create a simple batch application (running in the console).
It seems to me that to create this kind of project in this new realease I have to do:
File --> Spring Legacy Project --> Simple Spring Maven
It seems to me that there is no other way to create a simple console project. Why this kind of project are putted under the Spring Legacy Project? Can I do the same thing in a more modern way?
Another doubt is related to the Spring Version into the pom.xml file:
<spring-framework.version>3.2.3.RELEASE</spring-framework.version>
Why the default version is the 3.2.3.RELEASE? Can I replace it with the more m odern Spring 4^
As its name says "Spring Legacy Project" is a legacy functionality. It create old Spring projects.
Spring now is promoting Spring Boot applications, these applications have everything you need configured by default. You only need to add the dependencies that you need.
Now you need to use:
File -- > New -- Spring Starter Project
On the first view you configure the project. Where is located, maven or gradle, etc.
On the second view you choose the libraries that you will use in your porject. You choose if it is a web project, or if you need jdbc or jpa, or batch processing.
In your case, if you don't need a web application, you just don't added to the project.
You can see more about Spring boot here
https://projects.spring.io/spring-boot/
I'm using Eclipse (Neon.1) and Java 8. I know my way around Java and in the past I created Java projects by File > New > Java Project (for a POJO project). Or File > New > Dynamic Web Project (for a WAR web app project).
But today I want a project that uses Maven, Spring MVC, Spring ORM, JPA/Hibernate, and probably a couple of other things.
I'm confused about how to build this project in Eclipse.
Do I do File > New > Java Project ... and tweak it and add stuff to it?
Or do I File > New > Maven Project ... and tweak it and add stuff to it?
I've also heard that Spring Boot is a good way to get started with this kind of thing.
Any pointers or suggestions would be greatly appreciated!
I suggest you use spring boot. It's very easy to develop Spring Based applications with Java. It avoids writing lots of boilerplate code, Annotations and XML Configuration.
here's the link on how to use spring boot with maven.
https://spring.io/guides/gs/spring-boot/
The easiest way is probably using the Spring Initializr; That web interface is also provided in IDEs (cannot speak to how it's implemented in Eclipse though).
What you'll get is pom.xml file that you then can use to create a new maven project by pom file. It will load all the dependencies you choose and makes configuration simple.
I usually create a Maven Project and add any Stuff like Spring MVC, Hibernate to it. And Spring boot is highly recommended, no need to look at xml files anymore. Here is a archetype that may useful:
https://github.com/superalsrk/cn.stackbox.archetypes
Let me explan one by one.
java - programming language
Maven - Build tool and dependencies manager like npm or bower
Spring - A java framework witten top of java also contains java codes
Hibernate/JPA - is another framework in java helps to handle data access and store data in database
In eclipse You need to create a maven project which will creates the project structure. it will create a pom.xml file and then you need to add spring and jpa related dependencies.
Then maven will manage those dependencies and now you can write your programming logic to manage your data and UI.
You can refer sample project in git
You can install the m2e plugins (usually come along with eclipse already). And configure it according to your local maven installation.
And then create a web application skeleton based on the maven project templates/archetypes provided by the m2e plugin like the normal new project process.
And then you can edit the pom.xml file (Project Object Model, which is the maven project file) to include the packages you need, such as Spring, etc.
I don't have my dev machine at hand. So the above descriptions may be vague without proper screenshots. So please follow the below 2 quick guides. Hope they help.
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
https://web.liferay.com/community/wiki/-/wiki/Main/m2e-liferay+Quick+Start+Tutorial
And these:
Using Maven within the Eclipse IDE - Tutorial
Maven + Spring hello world example
Some examples related for requested technology stack:
Jersey + Spring example: https://www.mkyong.com/webservices/jax-rs/jersey-spring-integration-example/
Jersey + Hibernate + Spring example: http://www.benchresources.net/jersey-2-x-web-service-integrating-with-spring-and-hibernate-orm-framework-using-annotation/
As chaixxiv mentioned previously https://stackoverflow.com/a/40966438/5962766, to avoid boilerplate code you can use Spring Boot. More samples:
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/