Pages

2022年6月16日星期四

Variable Shadowing & 'this' Keyword

 Take a look at this piece of code




For those who remember boiler plate code, this code will looks strange because it hasn't 'this' keyword. But this code works fine


this keyword only needed and become obligatory when facing variable shadowing.



This is variable shadowing. The constructor method will never be able to modify class attributes, because attributes name is the same with parameter name (the variable name overridden). Therefore you need to use this keyword, so the compiler could distinguish the address belongs to the parameter, and which one belongs to the attributes

Note: When calling instance method, people usually use this keyword. It is not necessary actually


2022年6月14日星期二

HTTPS for Java Spring Boot

Using Lets Encrypt is not suitable for spring boot I think, because its certbot doing verification with static content, while you serving single jar file in your system (no /static folder). You should modify some project structure, and it sucks

Instead, you should go to ZeroSSL, choose verification via CNAME record instead of HTTP upload

Got your certificate!




After getting certificate, you should install it
in case you have Tomcat server, your Spring boot code will have server.xml
But mine is not, maybe because it is standalone jar file

so to install the cert, follow this guide:
https://medium.com/@marianfurdui/generate-a-java-keystore-from-lets-encrypt-for-java-web-spring-or-spring-boot-applications-bf07408158ef

from that guidance, you will get file ending in .p12

after which, you should set it up on your application.properties like so


souce: http://www.heydari.be/2016/05/14/Spring-Boot-Application-Secured-by-Lets-Encrypt-Certificate.html
dont forget to match your server.ssl.keyAlias with the -name you created previously (maybe its root or keybin or tomcat)



That was I long journey. I started at 05.30 and finish at 09.00. About 3,5 hours to get my instance up and run with HTTPS