CodeIn House

  • Laravel
  • WordPress
  • jQuery
  • Javascript
  • Contact
Home   JAVA   How to Setup and Run Spring Boot Application in Intellij IDE ...

How to Setup and Run Spring Boot Application in Intellij IDEA and Eclipse?

March 18, 2018 by SNK

enable jsp support in spring boot application with hello world example

Today we are going to learn how to setup spring boot application in intellij and eclipse. It is very easy to use and using spring boot we can easily develop enterprise level application on the go.

My personal favorite go to IDE is intellij since it has many shortcuts and easy to use, but most prefer eclipse as well. So we are going to have both tutorial on how to setup and run spring boot application using intellij and eclipse.

Lets get started.

First we are going to see how to use intellij IDEA to setup a spring boot application project. It has an inbuilt feature to create an spring boot project using spring initializer which makes us really easy to set up the project in no time at all.

Setting Up Spring Boot Project / Application with Intellij IDEA

Run intellij IDEA and click create new project or File > New > Project.

After that it select spring initializer and click next selecting default radio button.

select spring initializer option

In this part you will be allowed to choose dependencies that you would like to use it in your project. Select according to the category below and press next.

  1. Core – DevTools, Security
  2. Web – Web, RestRespositories
  3. SQL – JPA, MySQL, JDBC

Time to fill up the information for your project. Take a look below.

setting up spring boot project information

Press Next and give the folder name for your project and the path where you want to save it.

Press next and wait while spring initializer starts to setup your project and download all dependency that are needed to require to run the spring boot application.

Voila, its ready.

Now, check for the folder in your project directory, you will find the java class named SpringbootApplication.java

Open it and right click >  Run Spring Boot Application.

Running SpringBootApplication

One of the wonderful things that comes with spring boot is that embedded tomcat server dependency which allows us to directly run project into the server without having to configure it.

It will be up and running in less than a minute or two.

When you run your application, sometimes it may fail to start showing you this kind of error like below :-

Spring JDBC Datasource ERROR

We are using spring-jdbc and jpa so our application requires to have configured datasource url in order to proceed. That’s why we need to specify the configuration for datasource.

Create new class where SpringBootApplication.java is name it AppConfig.java and annotate it with @Configuration annotation.

AppConfig.java
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.codeinhouse.springboot;
 
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
 
import javax.sql.DataSource;
 
@Configuration
public class AppConfig {
 
    @Bean
    public DataSource dataSource(){
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/dbname");
        dataSource.setUsername( "root" );
        dataSource.setPassword( "" );
        return dataSource;
    }
 
}

 

Run it again and check your application in the browser & it will run successfully on port 8080 by default.

Setting Up Spring Boot Project / Application with Eclipse

Setting up spring boot application is pretty straight and forward in eclipse too. What i hate about eclipse is that its damn slow than intellij but has many easy shortcuts to work with.

Open your browser and go to https://start.spring.io/

Take a look at the image below and fill in the options.

Get Existing Maven Project From Spring Official Website

Press Generate and a zip with a artifact id which would be app in our case will be downloaded. Extract it in the place where you want your project to be saved.

Open Eclipse and Go to File > Import and type maven and select existing maven project.

import maven project

Press next and click browse and select the directory where you have just extract the app.zip that you have just downloaded. It will look for pom file inside it, after all steps click finish.

browse for maven project directory

If you notice bottom right corner of the your eclipse IDE you will see that eclipse setting up your project. Wait till it gets 100%.

From the project explorer expand your project and expand src/main/java and open AppApplication.java and right click > Run as AppApplication.java

Thats, it run and you will finally have spring boot setup and ready to build real world application using spring boot. Must not forget that we need to configure datasource url also like we did in intellij IDEA.

SHARE ON
Buffer

Enjoyed this article?

Like us on

JAVA how to run spring boot application in intellij import intellij spring boot project

Avatar for SNK

About SNK

Hello Welcome to my Blog. I develop Websites Using Laravel Framwork & WordPress. Get Latest updates on Facebook | Twitter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get Connected !! With Us

TOP POSTS

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

TUTORIALS TILL DATE

  • September 2022 (6)
  • June 2021 (7)
  • October 2020 (5)
  • September 2020 (6)
  • September 2018 (14)
  • August 2018 (3)
  • July 2018 (4)
  • March 2018 (8)
  • February 2018 (5)
  • January 2018 (1)
  • December 2017 (2)
  • August 2017 (8)
  • May 2017 (1)
  • April 2017 (1)
  • March 2017 (4)
  • February 2017 (3)
  • January 2017 (4)

CATEGORIES

  • Angular (2)
  • CSS3 (3)
  • D3 (3)
  • HTML5 (7)
  • JAVA (11)
  • Javascript (20)
  • jQuery (8)
  • Laravel (35)
  • Others (3)
  • PHP (11)
  • Spring (2)
  • WordPress (10)

Top Categories

  • Angular
  • CSS3
  • D3
  • HTML5
  • JAVA
  • Javascript
  • jQuery
  • Laravel
  • Others
  • PHP
  • Spring
  • WordPress

Get in Touch

DMCA.com Protection Status

Recent Articles

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

© 2012-22 CodeIn House.  •  All Rights Reserved.