jexhuang
9/6/2018 - 7:24 AM

Spring boot without tomcat with thymeleaf

<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml"
	layout:decorate="~{layout}">

<head>
<title>Home Page</title>
<meta name="viewport"
	content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
	<div class="login" layout:fragment="content">
		<form method="post" action="/login" class="ui form login">
			<div class="ui card">
				<div class="content">
					<h2 class="ui orange dividing header">登入</h2>
					<br> <input type="hidden" name="_csrf"
						value="IA9AwF12-Ss0_aR36AkcJuoy1pixNM307Fwg">
					<div class="field">
						<label>公司帳號</label><input type="text" name="partner_account">
					</div>
					<div class="field">
						<label>使用者信箱</label><input type="email" name="email">
					</div>
					<div class="field">
						<label>使用者密碼</label><input type="password" name="password"
							autocomplete="off">
					</div>
					<div class="field">
						<div class="ui checkbox login-partner-account">
							<input type="checkbox" name="remember_partner_account"
								tabindex="0" class="hidden"><label>記住公司帳號</label>
						</div>
						<a href="/preResetPassword" class="ui right floated">忘記使用者密碼?</a>
					</div>
				</div>
				<div class="content">
					<button type="submit"
						class="ui right floated mediumn button orange inverted login-btn">登入</button>
					<a href="/register"
						class="ui right floated button mediumn orange inverted">註冊</a>
				</div>
			</div>
		</form>
	</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE">ECNEX</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{/css/semantic.min.css}">
<link rel="stylesheet"
	href="https://portal.tappaysdk.com/css/all.min.css">
</head>
<body>
	<div class="main-body">
		<div class="header-bar">
			<div class="header-content">
				<a href="/"><img
					src="https://upload.wikimedia.org/wikipedia/zh/2/2f/NCCC_logo.gif"
					class="ui bottom aligned small image"
					style="height: 50px; width: auto;"></a> 
				<label style="font-size: 35px;color:white">NCCC</label>
			</div>
		</div>

		<div layout:fragment="content"></div>
	</div>
	<script src="https://code.jquery.com/jquery-3.1.1.min.js"
		integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
		crossorigin="anonymous"></script>
	<script th:src="@{/js/semantic.min.js}"></script>
	<script src="https://portal.tappaysdk.com/js/all.min.js"></script>
</body>
</html>
system.env=develop_local
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:xe
spring.datasource.username=ecnex_local
spring.datasource.password=ecnex_local
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.jpa.database-platform = org.hibernate.dialect.Oracle10gDialect

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.maximumPoolSize=10

spring.jpa.show-sql=true
logging.config=classpath:develop_local/log4j2.xml
spring.banner.location=classpath:develop_local/banner.txt

spring.thymeleaf.cache=false
package com.nccc.ecnex_mcht;

import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.nccc.ecnex_mcht.model.dao.EcnexMerchantDao;
import com.nccc.ecnex_mcht.model.entity.EcnexMerchant;
import nz.net.ultraq.thymeleaf.LayoutDialect;

@SpringBootApplication
@Controller
public class DemoApplication extends SpringBootServletInitializer {

	@Autowired
	private EcnexMerchantDao dao;

	@RequestMapping(value = "test")
	@ResponseBody
	public String test() {
		Optional<EcnexMerchant> merchant = dao.findById(7l);
		return merchant.get().toString();
	}

	@RequestMapping(value = "index")
	public String index() {
		return "index";
	}

	@Bean
	public LayoutDialect layoutDialect() {
		return new LayoutDialect();
	}

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

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

apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootWar {
    baseName = 'ecnex-mcht'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8

repositories {
	mavenCentral()
}


dependencies {
	providedCompile 'javax.servlet:javax.servlet-api:3.0.1' // Compiler level
    providedRuntime 'javax.servlet:jstl:1.2'    // Runtime level
	compile('org.springframework.boot:spring-boot-starter-data-jpa'){
    	exclude module: 'spring-boot-starter-logging'
    }
	compile('org.springframework.boot:spring-boot-starter-web'){
    	exclude module: 'spring-boot-starter-logging'
    	exclude module: 'spring-boot-starter-tomcat'
    }
	compile('org.springframework.boot:spring-boot-starter-log4j2')
	compile('org.springframework.boot:spring-boot-starter-thymeleaf'){
    	exclude module: 'spring-boot-starter-logging'
    }
	compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0')
	compile fileTree(dir: "libs", include: '*.jar')
	testCompile('org.springframework.boot:spring-boot-starter-test')
	compile("org.springframework.boot:spring-boot-devtools")
}