I have create sample jHipster app. Now I want to add self signed SSL certificate and test in local to have a access to https. How to achieve this?
相关问题
- Dependency injection into Logback Appenders with S
- Deserialize duplicate keys to list using Jackson
- How can I access the repository from the entity in
- Prevent Swagger from automatically adding some mod
- Creating Unknown Number of Beans With Configuratio
相关文章
- How to load @Configuration classes from separate J
- Mapstruct generated class not being injected by Sp
- Using Spring Dynamic Languages Support from Groovy
- Spring JMS : Set ErrorHandler for @JmsListener ann
- ModelMapper: Choose mapping based on Child class
- Configure Spring for CORS
- Remove transitive classpath dependency in gradle
- SpringBoot When file upload size limit exceeds get
These instructions are applicable for all Spring Boot applications, on which JHipster is based. I have tested this on a newly generated JHipster 2.7 project.
You need to complete these steps when starting from scratch:
Generating a self-signed certificate
First you need to generate your self-signed certificate in your project directory, this can be done with
keytool
, which is utility script provided by Java:I have chosen password
mypassword
so this is the one I will use in the next step. When you have done this, you will see akeystore.p12
in your current directory.Add the SSL properties to your
application.properties
orapplication.yml
as mentioned in the Spring Boot documentationNow you need to add the HTTPS connector properties for Tomcat. You can find the property (yml) files in
src/main/resources/
and you need to update theapplication.yml
(or if it is only for development inapplication-dev.yml
with the following properties:Now you can package your application with Maven (or Gradle if you chose that for your JHipster application) using
mvn clean package
and run the application using mvn spring-boot:run. You can now access your application on https://localhost:8080For simplicity I did not change the port, but ideally you should change it as well in the properties files, but I left it out since they are already defined in
application-dev.yml
andapplication-prod.yml
so you would have to change it in there or remove it and put it in the generalapplication.yml
(Optional) Add redirect HTTP to HTTPS
You can only enable one protocol through the
application.properties
, so when you do this like above only HTTPS will work. If you want HTTP to work too, and redirect to HTTPS you have to add a@Configuration
class like belowThis response is basically a copy of my blog post on the same subject: http://www.drissamri.be/blog/java/enable-https-in-spring-boot/
To extend the Driss Amri brilliant answer on how to re-enable
BrowserSync
.If you choose not to support http, or if http is redirected to https,
BrowserSync
will not work. To make it work again, few changes are necessary in:gulp/config.js,
apiPort
anduri
to:gulp/serve.js: add
options.rejectUnauthorized = false;
intoproxyRoutes
so that node does not complain about self signed certificate:optionally let
BrowserSync
serve content over https too. I recommend it withSpring Social
to save some trouble. Just addhttps: true
intobrowserSync
call in gulp/serve.js:Now BrowserSync will serve content with self signed certificate shipped with it. It is possible to reuse the one created for
Spring Boot
, more on BrowserSync homepage.For those using webpack instead of gulp you can complete Driss Amri's answer with two changes:
modify the proxy.conf.json:
this will redirect API requests to the new https address. Then alter also webpack file for instance here a webpack.dev.js modified example: