반응형
개발환경 | |
Os | Windows 10 |
IDE | STS 3.9.5 |
Jdk | 1.8.0_172 |
Spring | 5.0.9.RELEASE |
View | Thymeleaf |
1.File > New > Spring Starter Project
2. 프로젝트의 사용할 Dependency 선택
- 저는 뷰단을 JSP가아닌 Thymeleaf 를 사용하기위해 Thymeleaf를 추가
3. run as > spring boot app
-
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured
- 아래와같이 에러가 떨어지는 것은 SpringBoot는 어플리케이션이 시작될 때 필요한 기본 설정들을 자동으로 설정하게 되어있는데, 그중에
DataSource 설정이 자동구성 될 때 필요한 데이터베이스 정보가 설정되지 않아 발생하는 문제다.
해결방법 - http://lemontia.tistory.com/586
- 프로젝트안에 Application.java 에 아래와같이 추가
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 Devhjblog1Application { public static void main(String[] args) { SpringApplication.run(Devhjblog1Application.class, args); } }
4. 웹페이지를 띄우기위한 Controller 생성
import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class WebTestController { @RequestMapping("/") public String mainTest(Model model) { model.addAttribute("message","Spring Boot Main"); return "main"; } }
5. 테스트를위해 Thymeleaf 로 main.html 생성
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <!-- 사용자 CSS 추가 --> <th:block layout:fragment="css"> </th:block> <!-- 사용자 스크립트 추가 --> <th:block layout:fragment="script"> </th:block> <span th:text="${message}">${message}</span> </html> |
6. run as > spring boot app
7. 디렉토리 구조
8. pom.xml (20180927 추가)
<?xml version="1.0" encoding="UTF-8"?> 4.0.0 com.devhjblog devhjblog 0.0.1-SNAPSHOT war devhjblog Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 2.0.5.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-websocket org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2 mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-tomcat provided org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-thymeleaf nz.net.ultraq.thymeleaf thymeleaf-layout-dialect org.springframework.boot spring-boot-maven-plugin
반응형
'Spring' 카테고리의 다른 글
Intellij Spring boot Jmx RMI remote objects have benn exported (0) | 2022.09.13 |
---|---|
Spring + Mssql + Mybatis 연동 (0) | 2019.12.03 |
Spring Security 구성하기(2) - 패턴구분 및 로그아웃 (0) | 2019.11.26 |
Spring Security 구성하기(1) (0) | 2019.11.26 |
Spring Boot + Maven 웹프로젝트 시작하기_ application.properties 설정 (0) | 2018.10.01 |
댓글