728x90
반응형
SMALL
📌 실행해보기
1. 패키지를 하나 만든다. = com.cos.blog.test
2. 그안에 클래스를 하나 만든다. = com.cos.blog.test
3. 클래스안에 내용을 기입한다.
package com.cos.blog.test;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
// 스프링이 com.cos.blog패키지 이하를 스캔해서 모든 파일을 메모리에 new하는 것은 아니고,
// 특정 어노테이션이 붙어있는 클래스 파일들을 new해서(ioc) 스프링 컨테이너에 관리해준다.
@RestController
public class BlogControllerTest {
@GetMapping("/test/hello")
public String hello() {
return "<h1>hello spring boot</h1>";
}
}
4. Run AS - Spring boot app을 눌러 실행하기
5. If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. gradle 오류발생
- run as를 실행시켰는데도 console창에 저런식으로 오류가 발생했다.
구글링 해보니 DataSource 설정이 제대로 되어 있지 않아서 그런 것이었다.
- 일단 이러한 에러가 발생하는 이유는 Spring Boot 에서는 DataSource 를 필요로 하는 의존성이 추가만 되어도
자동으로 DataSource 생성을 시도하기 때문이다.
- 아직 프로젝트에 대해 DB정보가 확정되지 않았기 때문에 H2 Database 의존성을 추가하여 해결할 수 있다
- 이 의존성을 추가하면 application.yml 에 별도로 정의된 DataSource 정보가 없다면 내부적으로 H2 Database가 실행되어 이에 대한 DataSource 를 생성하게 된다.
- dependecies에 아래와 같이 의존성을 추가한다.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation "com.h2database:h2"
implementation 'javax.servlet:jstl' // JSTL
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper' // JSP 탬플릿 엔진
implementation 'org.springframework.security:spring-security-taglibs' // Security 태그 라이브러리implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
}
6. 저장하고 다시 실행해보기.
strated blogapplication이 뜨면서 run이 잘되는 것을 볼수있다.
728x90
반응형
LIST
'Spring > Spring 블로그만들기' 카테고리의 다른 글
[Springboot] 나만의 블로그 만들기 - 6. Git 세팅 (0) | 2022.03.08 |
---|---|
[Springboot] 나만의 블로그 만들기 - 5. MySQL 스프링 연결 (0) | 2022.03.07 |
[Springboot] 나만의 블로그 만들기 - 4. MySQL 세팅하기 (0) | 2022.03.07 |
[Springboot] 나만의 블로그 만들기 - 2. 의존성 설정 (0) | 2022.03.07 |
[Springboot] 나만의 블로그 만들기 - 1. 환경세팅 (0) | 2022.03.07 |