spring-boot

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
mkdir spring-boot
cd spring-boot

# http://repo.spring.io/release/org/springframework/boot/spring-boot-cli/
wget http://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.5.2.RELEASE/spring-boot-cli-1.5.2.RELEASE-bin.zip
unzip spring-boot-cli-1.5.2.RELEASE-bin.zip

set path=%path%;C:\Users\leon\spring-boot\spring-1.5.2.RELEASE\bin
spring --version

set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 -Dinput.encoding=UTF-8 -Duser.language=en -Xverify:none -Duser.timezone=Asia/Taipei -XX:+UseStringDeduplication
set SERVER_PORT=8099
spring init --dependencies web,jpa,jdbc rest-cli
cd rest-cli
mvn clean compile
mvn package
mvn test
~~mvn deploy~~
mvn spring-boot:run -Dserver.port=8099
run
repackage
start
stop
build-info
java -jar target\rest-cli-0.0.1-SNAPSHOT.jar
mvn exec:java -Dexec.mainClass=com.example.DemoApplication
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.38</version>
</dependency>    

<dependency>
  <groupId>org.hsqldb</groupId>
  <artifactId>hsqldb</artifactId>
</dependency>    

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>${h2.version}</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

@SpringBootApplication
@RestController
public class DemoApplication {

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

@RequestMapping("/greet")
public String hello(){
return "Hello REST!!!";
}
}

application.properties:

# @see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html
server.port = 8099
java.version=1.7

#mysql
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#h2
#spring.datasource.url = jdbc:h2:mem:app_db;DB_CLOSE_ON_EXIT=FALSE
#spring.datasource.url = jdbc:h2:file:~/h2/app_db;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;Mode=Oracle
spring.datasource.platform=h2
spring.datasource.continue-on-error=true

spring.jpa.hibernate.ddl-auto=update

spring.jpa.hibernate.ddl-auto=none
spring.profiles.active=h2

example

http://mycuteblog.com/h2-database-example-hibernate-spring-boot/