跳到主要內容

發表文章

目前顯示的是有「Spring-boot」標籤的文章

Spring-boot Thymeleaf Html5 SAXParseException 解析錯誤

thymeleaf 解析 html5 出錯 <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <title>SB Admin - Start Bootstrap Template</title> <!-- Bootstrap core CSS--> <link href="../static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <!-- Custom fonts for this template--> <link href="../static/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <!-- Page level plugin CSS--> <link href="../static/vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet"> <!-- Custom styles for this template--> <li...

Spring boot with docker

Spring boot with docker Spring-boot 官方教學: https://spring.io/guides/gs/spring-boot-docker/ , 做法跟設定跟官方教學有些不太一樣, 不考慮用 maven plugin 維護 docker images, 方便 devOps 統一管理。 Set up Spring-boot 先建立 spring-boot 專案, 專案命名為 demo-docker-spring 建立 controller, 簡單 echo Hello Docker World package com.example.demo; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Created by jerry on 2018/1/15. * * @author jerry */ @Slf4j @RestController public class Controller { @RequestMapping("/") public String home() { return "Hello Docker World"; } } Dockerfile docker 官方不支援 oracle-java, 所以找了一個 star 較高的 image 來用。 Dockerfile 就直接放在專案底下。 # https://hub.docker.com/_/java/ 不支援 oracle-java # FROM: 指定 base image (https://hub.docker.com/r/cogniteev/oracle-java/) FROM cogniteev/oracle-java # expose 8080 port EXPOSE 8080 # 複製當前路徑所有資料, 到容器裡面 COPY . /usr/app/demo-...

Setting maven liquibase plugin of Spring-boot

Liquibase Migration Laravel 的 Migration 是一個很棒的工具, 可以簡單的下個指令, 輕鬆的建立 tables php artisan migrate 在 Spring-boot 也提供一套類似的工具, 使用起來大同小異, 只是設定上有點小麻煩。 dependencies <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> </dependency> build <build> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> </testResource> </testResources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifa...

Let'sEncrypt with Spring-boot Https

網路管理基礎 Route53 與網路管理基本概念 EC2 Https 設定 AWS 綁定 Domain Route53 建立 Hosted Zones, 自己申請的 Domain (my-domain.me) Route53 Hosted Zones 建立 Record (my-domain.me), 綁定 EC2 Let’sEncrypt Certificate 申請 1. 安裝 certbot 工具 $ git clone https://github.com/certbot/certbot.git $ cd certbot $ ./certbot-auto 2. 透過 certbot 的 plugin 申請 certificate $ ./certbot-auto certonly —a standalone -d my-domain.me —email someone@gmail.com 在流程中, 需要回答一些問題, LetsEncrypt 會發送 request 去驗證 my-domain.me 這個 domain 3. 使用 openssl 將 letsEncrypt 的 key 產生 ssl 這是 os 環境 letsencrypt 的預設目錄路徑 $ cd /etc/letsencrypt/live/my-domain.me 把 letEncrypt 給你的 private key 產生 ssl 憑證 $ openssl pkcs12 -export -in fullchain.pem \ -inkey privkey.pem \ -out keystore.p12 -name tomcat \ -CAfile chain.pem \ -caname root 把生成的 ssl 憑證, 放到 spring-boot 專案底下的 resouces $ cp keystone.p12 ~/my-web-project/main/resources/ 4. 設定 application-prod.yml server: port: 8443...

Spring boot Https 設定

1. 產生 SSL certificate keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650 Enter keystore password: Re-enter new password: What is your first and last name? [Unknown]: jerry What is the name of your organizational unit? [Unknown]: td What is the name of your organization? [Unknown]: com What is the name of your City or Locality? [Unknown]: taipei What is the name of your State or Province? [Unknown]: taiwan What is the two-letter country code for this unit? [Unknown]: tw Is CN=jarvis, OU=td, O=urad, L=taipei, ST=taiwan, C=tw correct? [no]: yes 這個 certificate 是 self-signed certificate 沒有經過第三方認證, 所以沒有公信力, 正式上線會在瀏覽器看到 連線不被信任 要有公信力的 certificate 最簡單的是 Lets Encrypt , 其他就是花一些錢找簽發 certificate 的組織 2. Enable HTTPS in Spring Boot Spring Boot 內建的 tomcat 預設 http 是 8080, Spring Boot 可以設定 http 跟 https, 但沒辦法同時存在這兩個設定, 如果要同時存在兩種 connection, 建議依照 文件 建議設定 https, 再透過 programmatically 去設定 http 會比較容易。 相關範例可以參考 : https://...