woong's

Spring Tutorial 프로젝트 생성하기 01 본문

Develop/Server

Spring Tutorial 프로젝트 생성하기 01

dlsdnd345 2016. 4. 28. 21:04
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Spring Tutorial 프로젝트 생성하기 01


Spring 2.x , 3.x 과도기때 스터디를 통해서 공부를 했었는데.. 모바일 프로젝트만 하다보니

학습 했던 것을 잃어버려 다시 학습하고 정리하고자 포스트를 작성합니다.


이전에는 서버 설정 작업이 정말 어려웠는데 Spring Tool suite 를 사용하여 잠깐 사용해 본 결과

설정 작업의 많은 부분을 자동화 시켜 놓아 서버 작업하기 용이하게 바뀐것 같습니다.


처음 프로젝트 생성 < DAO 생성 < Service < Transaction < Controller

까지 속성으로 포스트를 작성해 보려 합니다.





Spring Starter Project 를 선택해서 프로젝트를 생성합니다.




프로젝트 이름 , 패키지 정보를 입력 하고 다음으로 넘어 갑니다.

여기서 Type 을 지정할수 있는데 

Maven , Gradle 이 있습니다. 최근에 Gradle 을 많이 사용하고 있는 추세 입니다.

Android 역시 Gradle 을 이용하고 있구요. 하지만 이번에는 익숙한 Maven 으로 진행 해보려합니다.

한번에 많은것을 하면 오히려 산으로 갈것 같아 하나씩 바꾸어 보려 합니다.






이화면이 Spring Starter Project 의 장점 인것 같습니다.

필요로 하는 항목을 선택하면 자동으로 dependency 가 추가 되어서 따로 찾아가며

추가 하는 번거로움을 덜어 주는것 같습니다. 저는 이전에 스터디 할때 하이버 네이트 를 사용했습니다.

또한 Spring Boot 에서 ORM을 권장 하는것 같습니다.


그래서 JPA ,Web , H2 를 추가 하였습니다.


H2(Java SQL database , 메모리 기반의 데이터베이스)




생성된 프로젝트 구조는 위와 같습니다.



src > main > java : java class

src > main > resources : view Template(templates 폴더), resource(static 폴더), properties 구현

src > test > java : test 코드 java class


생소한 Application , application.properties 가 있습니다.



1. Application 


단독 실행 및 스크립트 실행을 지원

@SpringBootApplication 어노테이션 안에

 - Configuration

 - ConponentScan

 - EnableAutoConfiguration 등의 어노테이션이 등록되어 있습니다.


Spring Boot 의 코드를 작성해보면 이전과는 달리 DAO , Service 등을 사용할때

Scan을 따로 등록하지 않아도 되는점이 @SpringBootApplication 어노테이션 안에 있었네요.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Configuration
@EnableAutoConfiguration
@ComponentScan
public @interface SpringBootApplication {
 
    /**
     * Exclude specific auto-configuration classes such that they will never be applied.
     * @return the classes to exclude
     */
    Class<?>[] exclude() default {};
 
    /**
     * Exclude specific auto-configuration class names such that they will never be
     * applied.
     * @return the class names to exclude
     * @since 1.3.0
     */
    String[] excludeName() default {};
 
    /**
     * Base packages to scan for annotated components. Use {@link #scanBasePackageClasses}
     * for a type-safe alternative to String-based package names.
     * @return base packages to scan
     * @since 1.3.0
     */
    @AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
    String[] scanBasePackages() default {};
 
    /**
     * Type-safe alternative to {@link #scanBasePackages} for specifying the packages to
     * scan for annotated components. The package of each class specified will be scanned.
     * <p>
     * Consider creating a special no-op marker class or interface in each package that
     * serves no purpose other than being referenced by this attribute.
     * @return base packages to scan
     * @since 1.3.0
     */
    @AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
    Class<?>[] scanBasePackageClasses() default {};
 
}
 
 
 
cs


2. application.properties


application.properties 파일은 외부요인들을 읽어 오게 되는 역할을 하게 됩니다.

통상 DB 의 설정 작업이 작성됩니다. 처음에는 비어 있네요.



결론


이와같이 간단하게 프로젝트 생성만으로 굉장히 많은 것을 설정이 되었습니다.

Spring Boot 로 접근하면 잘 모를수 있지만 , 이전부터 개발하신분들은 아마 너무 간단해졌다고 느낄수 있습니다.

이프로젝트에 DB 설정만 적용하면 간단하게 서버를 구성 할수 있습니다. 다음 포스트에서는 DB를 구성해 보려합니다.


Server Spring Tutorial Sample 








Comments