Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yookeun committed Oct 7, 2017
0 parents commit e424730
Show file tree
Hide file tree
Showing 28 changed files with 748 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.gradle
/build/
*/bin/
/bin/
*/out/
/out/
!gradle/wrapper/gradle-wrapper.jar


### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.DS_Store

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

rebel.xml

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### gradle multi project

- gradle-multi-core : common library (dao, dto)
- gradle-multi-web : web application
- gradle-multi-app : app application
53 changes: 53 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//=================================================================//
// gradle-multi ROOT
//=================================================================//


buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE')
}
}


subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

sourceCompatibility = 1.8

repositories {
mavenLocal()
mavenCentral()
}

task initSourceFolders {
sourceSets*.java.srcDirs*.each {
if( !it.exists() ) {
it.mkdirs()
}
}

sourceSets*.resources.srcDirs*.each {
if( !it.exists() ) {
it.mkdirs()
}
}
}


dependencies {
compileOnly('org.projectlombok:lombok')
testCompile("org.springframework.boot:spring-boot-starter-test")
}

}
14 changes: 14 additions & 0 deletions doc/install_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use test_db;

create table board(
id int not null auto_increment,
title varchar(100) not null,
content text null,
regdate datetime not null,
primary key(id)
);

insert into board(title, content, regdate) values('title1', 'content1', now());
insert into board(title, content, regdate) values('title2', 'content2', now());
insert into board(title, content, regdate) values('title3', 'content3', now());

9 changes: 9 additions & 0 deletions gradle-multi-app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//=================================================================//
// gradle-multi-app
//=================================================================//

dependencies {
compile project(':gradle-multi-core')
compile('org.springframework.boot:spring-boot-starter-aop')

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.app;

import com.example.app.service.BoardAppService;
import com.example.core.board.dto.BoardDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.PostConstruct;
import java.util.List;

@SpringBootApplication
@ComponentScan("com.example")
public class GradleMultiAppMain {

@Autowired
private BoardAppService boardService;

public static void main(String[] args) {
SpringApplication.run(GradleMultiAppMain.class, args);
}

@PostConstruct
public void run() {
List<BoardDto> boardDtoList = boardService.selectList();
for (BoardDto boardDto : boardDtoList) {
System.out.println("title = " + boardDto.getTitle());
System.out.println("content = " + boardDto.getContent());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.app.control;

/**
* Created by yookeun on 2017. 10. 7..
*/
public class BoardAppController {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.app.service;

import com.example.core.board.dao.BoardDao;
import com.example.core.board.dto.BoardDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* Created by yookeun on 2017. 10. 7..
*/

@Service
public class BoardAppService {
@Autowired
private BoardDao boardDao;
public List<BoardDto> selectList() {
return boardDao.selectList();
}
}
17 changes: 17 additions & 0 deletions gradle-multi-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:
profiles:
active:
- ykkim
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test_db?useUnicode=true&characterEncoding=utf8
username: root
password: 1234
hikari:
maximum-pool-size: 10
max-lifetime: 30

security:
basic:
enabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.app.control;

import com.example.app.service.BoardAppService;
import com.example.core.board.dto.BoardDto;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
* Created by yookeun on 2017. 10. 7..
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class BoardAppControllerTest {


@Autowired
private BoardAppService boardAppService;

@Test
public void board_list() {
List<BoardDto> boardList = boardAppService.selectList();
for (BoardDto boardDto : boardList) {
System.out.println("title = " + boardDto.getTitle());
System.out.println("content = " + boardDto.getContent());
}
}

}
14 changes: 14 additions & 0 deletions gradle-multi-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//=================================================================//
// gradle-multi-core
//=================================================================//

bootRepackage {
enabled = false
}

dependencies {
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')
runtime('mysql:mysql-connector-java')
compile 'com.zaxxer:HikariCP:2.6.2'

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.core.board.dao;



import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.example.core.board.dto.BoardDto;

@Repository
public class BoardDao {
@Autowired
private SqlSession sqlSession;

public List<BoardDto> selectList() {
return sqlSession.selectList("boardMapper.selectList");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.core.board.dto;

import lombok.Data;

@Data
public class BoardDto {
private int id;
private String title;
private String content;
private String regdate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.core.config;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@ComponentScan("com.example")
public class MyBatisConfig {

// @Autowired
// private DataSource dataSource;

@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setConfigLocation(new DefaultResourceLoader().getResource("classpath:mybatis-config.xml"));
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
return bean.getObject();
}

@Bean
public SqlSessionTemplate sqlSession(SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}

@Bean
public DataSourceTransactionManager txManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
10 changes: 10 additions & 0 deletions gradle-multi-core/src/main/resources/mapper/boardMapper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="boardMapper">

<select id="selectList" resultType="boardDto" >
SELECT /* + boardMapper.selectList + */
id, title, content, regdate FROM board
</select>

</mapper>
23 changes: 23 additions & 0 deletions gradle-multi-core/src/main/resources/mybatis-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

<settings>
<setting name="cacheEnabled" value="false"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="true"/>
<setting name="useGeneratedKeys" value="true"/>
<setting name="defaultExecutorType" value="SIMPLE"/>
<setting name="defaultStatementTimeout" value="600"/>
<setting name="multipleResultSetsEnabled" value="true" />
<setting name="useColumnLabel" value="true" />
<setting name="safeRowBoundsEnabled" value="false" />
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>


<!-- Model 객체 Alias -->
<typeAliases>
<typeAlias alias="boardDto" type="com.example.core.board.dto.BoardDto"></typeAlias>
</typeAliases>
</configuration>
12 changes: 12 additions & 0 deletions gradle-multi-web/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID">
<display-name>gradle-multi-web</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
15 changes: 15 additions & 0 deletions gradle-multi-web/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//=================================================================//
// gradle-multi-web
//=================================================================//

apply plugin: 'war'

dependencies {
compile project(':gradle-multi-core')

providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'javax.servlet:jstl:1.2'
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')
testCompile('org.springframework.security:spring-security-test')
}
Loading

0 comments on commit e424730

Please sign in to comment.