스프링 부트로 프로젝트 만들기 (STS)
1. File->New->Spring Starter Project
Name: 프로젝트 이름
Type: Maven or Gradle
Group / Package: 패키지명
2. Spring boot version 선택 및 원하는 플러그인 선택해서 추가하기
Web을 선택하여 추가하였다.
처음에는 Web을 추가하지 않았다가 어노테이션 적용이 되지 않아서 헤매다가 다시 체크하고 추가했다.
꼭 체크해주기!
3. 프로젝트 생성 완료
TestApplication.java, application.properties 등을 스프링 부트에서 자동으로 만들어 준 것을 확인하였다.
많은 라이브러리들도 자동으로 추가되어있다.
Springboot 설치 시 서버를 함께 포함하고 있어서 따로 설정해줄 필요가 없어서 편리했다.
4. 제대로 작동하는지 확인해보기
TestController.java를 만들어 확인해보았다.
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping("/")
public String root() {
return "Spring boot Test";
}
}
2. 실행 시켜보기
@SpringBootApplication 어노테이션이 붙어있는 클래스 파일을 실행시키면 된다.
실행 시 아래와 같은 오류가 발생한다면
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
이와 같이 어노테이션을 추가시켜준다.
Springboot는 시작 시에 자동으로 기본적인 세팅을 해주는데, 이때 데이터베이스 설정이 되어있지 않아 발생하는 오류라고 한다.
application.properties가 현재는 빈 파일인데 어떤 데이터베이스를 사용할 것인지를 추후에 이곳에 설정하여 해결할 수도 있다.
[참고] https://lemontia.tistory.com/586
MySQL 설치는 아래 링크를 참고하였다.
https://nemew.tistory.com/15?category=745024
https://www.journaldev.com/13830/spring-boot-cannot-determine-embedded-database-driver-class-for-database-type-none
'ICT Intern > Springboot' 카테고리의 다른 글
[Spring] 연습용 소스코드 실행 및 웹 기초 정리 (0) | 2019.03.07 |
---|