Spring Cloud學習資源

Spring Cloud中文網:
https://springcloud.cc
https://springcloud.cc/spring-cloud-dalston.html

Spring Boot參考指南:
https://www.gitbook.com/book/qbgbook/spring-boot-reference-guide-zh/
https://qbgbook.gitbooks.io/spring-boot-reference-guide-zh/

Spring Cloud Stream Reference:
http://docs.spring.io/spring-cloud-stream/docs/Chelsea.SR2/reference/htmlsingle/
http://weifuwu.io/2016/09/15/dive-into-spring-cloud-stream/

Spring Cloud Task Reference:
http://docs.spring.io/spring-cloud-task/docs/1.2.0.RELEASE/reference/htmlsingle/

廣告

@Transactional 參數小技巧

1. DAO層get method最好都設定成readOnly=true, 預設值是false
2. synchronized不要加在DAO層, 應加在Service層
3. 如果synchronized method有@Transactional, 務必設定timeout

Spring Propagation types

Spring交易的屬性介紹

https://openhome.cc/Gossip/SpringGossip/TransactionAttribute.html

Propagation behavior:

MANDATORY
Support a current transaction, throw an exception if none exists.

Does not start a new Transaction, just checks whether a transaction is active (must be inside either another @Transactional method call or a programmatically created transaction)

NESTED
Execute within a nested transaction if a current transaction exists, behave likePROPAGATION_REQUIRED else.

Start a nested transaction if a transaction exists, start a new transaction otherwise.

NEVER
Execute non-transactionally, throw an exception if a transaction exists.

Does not start a transaction. Fails if a transaction is present.

NOT_SUPPORTED
Execute non-transactionally, suspend the current transaction if one exists.

Does not start a transaction. Suspends any existing transaction.

REQUIRED
Support a current transaction, create a new one if none exists.

If a transaction exists, use that, if not, create a new one. In 95% of cases, this is what you need.

REQUIRES_NEW
Create a new transaction, suspend the current transaction if one exists.

Always creates a new transaction, no matter if an existing transaction is present. If there is, it will be suspended for the duration of this method execution.

SUPPORTS
Support a current transaction, execute non-transactionally if none exists.

Can use a transaction if one is present, but doesn’t need one (and won’t start a new one either)

Authentication using certificates, Tomcat and Spring security

Use LDAPS for Spring Security:
http://l-lin.github.io/2014/09/09/Auth_with_certificates_Tomcat_spring/

– 顯示LDAPS certificate:
openssl s_client -showcerts -connect myserver:636
– 存成X509 certificate檔:
echo -n | openssl s_client -connect myserver:636 | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ > myserver.crt

– 儲存certificate到JRE: (預設密碼:changeit)
keytool -import -keystore /opt/jdk7/jre/lib/security/cacerts -alias myserver -file myserver.crt
– 刪除certificate:
keytool -delete -alias myserver -keystore /opt/jdk7/jre/lib/security/cacerts -storepass changeit

– Client certificate over SSL
http://stackoverflow.com/questions/875467/java-client-certificates-over-https-ssl

-Djavax.net.ssl.keyStoreType=pkcs12
-Djavax.net.ssl.trustStoreType=jks
-Djavax.net.ssl.keyStore=clientcertificate.p12
-Djavax.net.ssl.trustStore=gridserver.keystore
-Djavax.net.debug=ssl # very verbose debug
-Djavax.net.ssl.keyStorePassword=$PASS
-Djavax.net.ssl.trustStorePassword=$PASS

Spring Security: Active Directory setup

基本設定:
http://javarevisited.blogspot.tw/2011/11/ldap-authentication-active-directory.html

Kerberos vs NTLM:
http://infocenter.pentaho.com/help/index.jsp?topic=%2Fpdi_admin_guide%2Ftask_manual_msad_config.html