티스토리 뷰
String Boot의 개념
1. Maven or Gradle 둘중 하나는 알고있어야한다
2. Maven MultiProject로 작성
3. ※ 핵심 startup ( startup-web 등 설정해두면 알아서 필요한 라이브러리가 설정됨) 의존성 라이브러리 그룹화
4. AutoConfiguration (자동으로 설정) properties : JDBC라이브러리를 사용한다면 그안에 url, 값설정은 preperties같은 파일에 설정해두고 이 파일의 위치를 알려주면 알아서 값이 설정된다
5. CLI
6. actuator? : 어플리케이션 기본 관리기능 잘 사용하지않는다
Maven MultiProject
제일 부모가되는 프로젝트는 pom으로 만듬
그외 모듈들은 war로 만듬
컨테이너는 jar
부모의 pom.xml에 모듈들의 공통적인부분을 작성
각 모듈의 pom.xml에는 각 모듈이 필요한것만 작성
부모 프로젝트를 생성하면 그안에 모듈들이 물리적으로 생성된다
각 모듈에 작업하기위해서 각 모듈을 논리적으로 빼내서 작업할수있다. 부모프로젝트 안의 모듈 오른쪽클릭 -> import as project
JavaWeb-Study
spring-study
l---- spring-study-hellospring1 (xml)
l---- spring-study-hellospring2 (java config)
l---- spring-study-hellospring3 (initializer, javaconfig)
l---- spring-study-emaillist3 (xml)
l---- spring-study-emaillist4 (
l---- spring-study-guestbook3
l---- spring-study-mysite3
l---- spring-study-mysite4
spring-boot
ㅣ--- spring-boot-hellospring
ㅣ--- spring-boot-emailist
ㅣ--- spring-boot-mysite
src/main/java
com.douzone.hellospring.bootstrap
com.douzone.hellospring.controller
src/main/resources // 디테일한 값들 세팅할때
application.properties
src/main/webapp (이걸 jar로 만들고 올릴때는 src/main/java, src/main/resources가 클래스즈 밑에 오도록 플러그인달고 war로만들어서 올림)
assets
WEB-INF
Spring Boot Project 만들기
1. spring-boot라는 이름의 부모 프로젝트 생성 ( pom )
2. spring-boot의 pom.xml에 spring boot starter를 등록
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
3. spring-boot에 모듈 추가 spring-boot-hellospring ( jar )
4. hellospring2의 controller 패키지를 복사하여 src/main/java에 붙여넣음
5. src/main 밑에 webapp 폴더 생성
6. hellospring2의 webapp안의 WEB-INF 폴더를 복사하여 src/main/webapp에 붙여넣음
7. spring-boot-hellospring의 pom.xml에 아래와 같이 설정한다
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency> <!-- 톰캣이 jsp변경되었는지 감시하고 컴파일 해주는 --> <!-- 이걸해주면 기본 jstl viewresolver가 설정됨 -->
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
jstl과 jasper를 등록하면 기본 viewResolver가 설정된다
8. src/main/java 밑에 com.douzone.hellospring.bootstrap 패키지 생성
9. BootApplication.class 작성 ( jar이기때문에 main포함하여 생성)
//@SpringBootConfiguration // spring-boot 설정파일이라고 알려주는거
//@EnableAutoConfiguration // 자동으로 설정
//@ComponentScan("com.douzone.hellospring.controller") // 부트 어플리케이션이있는 위치부터 아래로 쫙 스캔
/*
* @SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.douzone.hellospring.controller")
위 3개를 하나에 대신할수있는거
@SpringBootApplication
*/
@SpringBootApplication // spring boot 1.8 이상부터 작동
// 패키지이름을 com.douzone.hellospring 이라고해주면 이 아래에 모든것을 다스캔
public class BootApplication {
public static void main(String[] args)
{
SpringApplication.run(BootApplication.class, args);
}
}
properties 설정이 어렵다면 yaml 사용
10. DB를 사용한다면 모듈의 pom.xml에 아래의 내용 추가
<!-- mybatis starter -->
<dependency> <!-- 부모가 없어서 버전을 지정 -->
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
//<version>5.1.38</version>
</dependency>
version은 만약 spring boot와 버전이 맞지않다면 5.1.38버전 사용
11. src/main/resources 밑에 mybatis 폴더 생성
12. mybatis 밑에 mappers 폴더와 configuration.xml 파일을 mysite5에서 복사하여 붙여넣기
13. src/main/resources 밑에 application.properties 파일에 아래 내용 추가
# data source
spring.datasource.url=jdbc:mysql://localhost:3306/webdb?characterEncoding=utf8&aserverTimezone=UTC
spring.datasource.username=webdb
spring.datasource.password=webdb
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# mybatis
mybatis.config-location=classpath:mybatis/configuration.xml
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation -->
<!-- Validation -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-json -->
<!-- Jackson -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
'Spring' 카테고리의 다른 글
StandardServletMultipartResolver 설정 (0) | 2019.04.29 |
---|---|
SLF4J Log 설정 (0) | 2019.04.27 |
spring boot + react 과정 (Eclipse) (0) | 2019.04.19 |
ServletContainerInitializer를 이용한 방법 (0) | 2019.03.22 |
spring-servlet.xml 과 applicationContext.xml 대신 Class 이용 (0) | 2019.03.20 |