[go: nahoru, domu]

Skip to content

Commit

Permalink
Updates after hacking with Josh Long
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Raible committed Feb 4, 2022
1 parent 6616ce7 commit 29500be
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 64 deletions.
63 changes: 22 additions & 41 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,20 @@ import org.springframework.nativex.hint.TypeHint;
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-native</artifactId>
<version>1.6.2</version>
<version>1.6.5</version>
</dependency>
----
+
Swagger doesn't seem to work with WebFlux. In my browser's console, it says:
+ And update `jhipster-dependencies` to `7.6.1-SNAPSHOT` (since it specifies 1.6.5). With 1.6.2, the following error happens:
+
----
Failed to load resource: the server responded with a status of 404 :8080/management/jhiopenapigroups
Parameter 0 of constructor in org.springdoc.nativex.core.SpringDocHints
required a bean of type 'org.springdoc.core.SwaggerUiConfigProperties' that could not be found.
----
+
With Spring MVC, things don't even start up when running `./mvnw`:
Swagger doesn't seem to work with WebFlux. In my browser's console, it says:
+
----
Parameter 0 of constructor in org.springdoc.nativex.core.SpringDocHints
required a bean of type 'org.springdoc.core.SwaggerUiConfigProperties' that could not be found.
Failed to load resource: the server responded with a status of 404 :8080/management/jhiopenapigroups
----
. Liquibase is https://github.com/spring-projects-experimental/spring-native/issues/620[not supported yet], but you can make it work by adding files from https://github.com/liquibase/liquibase/pull/2005[this pull request] to your `src/main/resources/META-INF/native-image/liquibase` directory.
Expand All @@ -220,48 +219,25 @@ required a bean of type 'org.springdoc.core.SwaggerUiConfigProperties' that coul

. If you're using JPA, https://docs.jboss.org/hibernate/orm/5.4/topical/html_single/bytecode/BytecodeEnhancement.html#_build_time_enhancement[configure Hibernate build-time bytecode enhancement]. Add the plugin right after the `spring-aot-maven-plugin`.
+
In `application.yml`, turn off automatic datasource initialization so Liquibase works:
In `application.yml`, turn off loading of SQL so Liquibase works:
+
[source,yaml]
----
spring:
...
jpa:
defer-datasource-initialization: true
sql:
init:
mode: never
----
+
This _almost_ works. Current error is:
Without this change, the following error happens:
+
----
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase':
Circular depends-on relationship between 'liquibase' and 'entityManagerFactory'
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer':
Circular depends-on relationship between 'dataSourceScriptDatabaseInitializer' and 'liquibase'
----
. Build with `./mvnw package -Pnative,prod -DskipTests`
. If you're using Spring WebFlux with R2DBC, we https://github.com/jhipster/generator-jhipster/pull/17277#issuecomment-993132173[haven't figured that one out yet].

////
I didn't make it this far because of the above error

Then, add the following `@JdkProxyHint` to you main application class.
+
[source,java]
----
@JdkProxyHint(
types = {
org.springframework.data.jpa.repository.support.CrudMethodMetadata.class,
org.springframework.aop.SpringProxy.class,
org.springframework.aop.framework.Advised.class,
org.springframework.core.DecoratingProxy.class
})
----
+
And, add the following to the top of the `User` entity
+
[source,java]
----
@EntityListeners(AuditingEntityListener.class)
----

. If Spring MVC, add names to any `@RequestParam` and `@PathVariable` annotations.
+
[source,java]
Expand All @@ -278,12 +254,17 @@ public ResponseEntity<?> logout(HttpServletRequest request, @AuthenticationPrinc
...
OidcIdToken idToken = oidcUser.getIdToken();
----
////
== Known Issues
- Liquibase no longer works. See `Error creating bean with name 'liquibase'` error above for more information.
- `-DskipTests` is needed for both Spring MVC and WebFlux. Might because by Mockito. Excluding it and deleting tests worked last time. Not with 0.11.2.
- `-DskipTests` is needed for both Spring MVC and WebFlux. This seems to be caused by Mockito.
- Creating a new `Post` or `Tag` in the `postgres-mvc` project doesn't work. The error is:
+
----
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Unable to perform requested lazy initialization
[com.mycompany.myapp.domain.Post.tags] - no session and settings disallow loading outside the Session
(through reference chain: java.util.Collections$UnmodifiableRandomAccessList[0]->com.mycompany.myapp.domain.Post["tags"])
----
- Several of JHipster's Administration features don't work: metrics, logs, API docs, and configuration.
- Metrics: `UnsupportedFeatureError: ThreadMXBean methods`
- Logs: `/management/loggers` returns HTML instead of JSON
Expand All @@ -298,4 +279,4 @@ org.springframework.http.converter.HttpMessageNotWritableException: No converter
java.lang.IllegalStateException: Failed to process lifecycle methods on bean definition with name 'h2TCPServer'
----
+
It might be possible to fix with a `@TypeHint` for `org.h2.tools.Server.class`. However, this class is not in the classpath by default.
It might be possible to fix with a `@TypeHint` for `org.h2.tools.Server.class`. However, this class is not on the classpath by default.
4 changes: 2 additions & 2 deletions angular-webflux/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<profile.tls />

<!-- Dependency versions -->
<jhipster-dependencies.version>7.6.0</jhipster-dependencies.version>
<jhipster-dependencies.version>7.6.1-SNAPSHOT</jhipster-dependencies.version>
<!-- The spring-boot version should match the one managed by
https://mvnrepository.com/artifact/tech.jhipster/jhipster-dependencies/${jhipster-dependencies.version} -->
<spring-boot.version>2.6.3</spring-boot.version>
Expand Down Expand Up @@ -141,7 +141,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-native</artifactId>
<version>1.6.2</version>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
7 changes: 3 additions & 4 deletions postgres-mvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<profile.tls />

<!-- Dependency versions -->
<jhipster-dependencies.version>7.6.0</jhipster-dependencies.version>
<jhipster-dependencies.version>7.6.1-SNAPSHOT</jhipster-dependencies.version>
<!-- The spring-boot version should match the one managed by
https://mvnrepository.com/artifact/tech.jhipster/jhipster-dependencies/${jhipster-dependencies.version} -->
<spring-boot.version>2.6.3</spring-boot.version>
Expand Down Expand Up @@ -150,11 +150,10 @@
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webmvc-core</artifactId>
</dependency>
<!--dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-native</artifactId>
<version>1.6.2</version>
</dependency-->
<version>1.6.5</version>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ResponseEntity<Blog> createBlog(@Valid @RequestBody Blog blog) throws URI
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/blogs/{id}")
public ResponseEntity<Blog> updateBlog(@PathVariable(value = "id", required = false) final Long id, @Valid @RequestBody Blog blog)
public ResponseEntity<Blog> updateBlog(@PathVariable(name = "id", value = "id", required = false) final Long id, @Valid @RequestBody Blog blog)
throws URISyntaxException {
log.debug("REST request to update Blog : {}, {}", id, blog);
if (blog.getId() == null) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public ResponseEntity<Blog> updateBlog(@PathVariable(value = "id", required = fa
*/
@PatchMapping(value = "/blogs/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<Blog> partialUpdateBlog(
@PathVariable(value = "id", required = false) final Long id,
@PathVariable(name="id", value = "id", required = false) final Long id,
@NotNull @RequestBody Blog blog
) throws URISyntaxException {
log.debug("REST request to partial update Blog partially : {}, {}", id, blog);
Expand Down Expand Up @@ -158,7 +158,7 @@ public List<Blog> getAllBlogs() {
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the blog, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/blogs/{id}")
public ResponseEntity<Blog> getBlog(@PathVariable Long id) {
public ResponseEntity<Blog> getBlog(@PathVariable("id") Long id) {
log.debug("REST request to get Blog : {}", id);
Optional<Blog> blog = blogRepository.findById(id);
return ResponseUtil.wrapOrNotFound(blog);
Expand All @@ -171,7 +171,7 @@ public ResponseEntity<Blog> getBlog(@PathVariable Long id) {
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/blogs/{id}")
public ResponseEntity<Void> deleteBlog(@PathVariable Long id) {
public ResponseEntity<Void> deleteBlog(@PathVariable("id") Long id) {
log.debug("REST request to delete Blog : {}", id);
blogRepository.deleteById(id);
return ResponseEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -27,11 +28,11 @@ public LogoutResource(ClientRegistrationRepository registrations) {
* {@code POST /api/logout} : logout the current user.
*
* @param request the {@link HttpServletRequest}.
* @param idToken the ID token.
* @param oidcUser the OIDC user.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and a body with a global logout URL.
*/
@PostMapping("/api/logout")
public ResponseEntity<?> logout(HttpServletRequest request, @AuthenticationPrincipal(expression = "idToken") OidcIdToken idToken) {
public ResponseEntity<?> logout(HttpServletRequest request, @AuthenticationPrincipal OidcUser oidcUser) {
StringBuilder logoutUrl = new StringBuilder();

String issuerUri = this.registration.getProviderDetails().getIssuerUri();
Expand All @@ -50,6 +51,7 @@ public ResponseEntity<?> logout(HttpServletRequest request, @AuthenticationPrinc
logoutUrl.append("?client_id=").append(this.registration.getClientId()).append("&returnTo=").append(originUrl);
} else {
// Okta
OidcIdToken idToken = oidcUser.getIdToken();
logoutUrl.append("?id_token_hint=").append(idToken.getTokenValue()).append("&post_logout_redirect_uri=").append(originUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<Post> createPost(@Valid @RequestBody Post post) throws URI
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/posts/{id}")
public ResponseEntity<Post> updatePost(@PathVariable(value = "id", required = false) final Long id, @Valid @RequestBody Post post)
public ResponseEntity<Post> updatePost(@PathVariable(name = "id", value = "id", required = false) final Long id, @Valid @RequestBody Post post)
throws URISyntaxException {
log.debug("REST request to update Post : {}, {}", id, post);
if (post.getId() == null) {
Expand Down Expand Up @@ -111,7 +111,7 @@ public ResponseEntity<Post> updatePost(@PathVariable(value = "id", required = fa
*/
@PatchMapping(value = "/posts/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<Post> partialUpdatePost(
@PathVariable(value = "id", required = false) final Long id,
@PathVariable(name = "id", value = "id", required = false) final Long id,
@NotNull @RequestBody Post post
) throws URISyntaxException {
log.debug("REST request to partial update Post partially : {}, {}", id, post);
Expand Down Expand Up @@ -159,7 +159,7 @@ public ResponseEntity<Post> partialUpdatePost(
@GetMapping("/posts")
public ResponseEntity<List<Post>> getAllPosts(
@org.springdoc.api.annotations.ParameterObject Pageable pageable,
@RequestParam(required = false, defaultValue = "false") boolean eagerload
@RequestParam(name = "eagerload", required = false, defaultValue = "false") boolean eagerload
) {
log.debug("REST request to get a page of Posts");
Page<Post> page;
Expand All @@ -179,7 +179,7 @@ public ResponseEntity<List<Post>> getAllPosts(
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the post, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/posts/{id}")
public ResponseEntity<Post> getPost(@PathVariable Long id) {
public ResponseEntity<Post> getPost(@PathVariable("id") Long id) {
log.debug("REST request to get Post : {}", id);
Optional<Post> post = postRepository.findOneWithEagerRelationships(id);
return ResponseUtil.wrapOrNotFound(post);
Expand All @@ -192,7 +192,7 @@ public ResponseEntity<Post> getPost(@PathVariable Long id) {
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/posts/{id}")
public ResponseEntity<Void> deletePost(@PathVariable Long id) {
public ResponseEntity<Void> deletePost(@PathVariable("id") Long id) {
log.debug("REST request to delete Post : {}", id);
postRepository.deleteById(id);
return ResponseEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<Tag> createTag(@Valid @RequestBody Tag tag) throws URISynt
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/tags/{id}")
public ResponseEntity<Tag> updateTag(@PathVariable(value = "id", required = false) final Long id, @Valid @RequestBody Tag tag)
public ResponseEntity<Tag> updateTag(@PathVariable(name="id", value = "id", required = false) final Long id, @Valid @RequestBody Tag tag)
throws URISyntaxException {
log.debug("REST request to update Tag : {}, {}", id, tag);
if (tag.getId() == null) {
Expand Down Expand Up @@ -110,7 +110,7 @@ public ResponseEntity<Tag> updateTag(@PathVariable(value = "id", required = fals
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/tags/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<Tag> partialUpdateTag(@PathVariable(value = "id", required = false) final Long id, @NotNull @RequestBody Tag tag)
public ResponseEntity<Tag> partialUpdateTag(@PathVariable(name="id", value = "id", required = false) final Long id, @NotNull @RequestBody Tag tag)
throws URISyntaxException {
log.debug("REST request to partial update Tag partially : {}, {}", id, tag);
if (tag.getId() == null) {
Expand Down Expand Up @@ -162,7 +162,7 @@ public ResponseEntity<List<Tag>> getAllTags(@org.springdoc.api.annotations.Param
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the tag, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/tags/{id}")
public ResponseEntity<Tag> getTag(@PathVariable Long id) {
public ResponseEntity<Tag> getTag(@PathVariable("id") Long id) {
log.debug("REST request to get Tag : {}", id);
Optional<Tag> tag = tagRepository.findById(id);
return ResponseUtil.wrapOrNotFound(tag);
Expand All @@ -175,7 +175,7 @@ public ResponseEntity<Tag> getTag(@PathVariable Long id) {
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/tags/{id}")
public ResponseEntity<Void> deleteTag(@PathVariable Long id) {
public ResponseEntity<Void> deleteTag(@PathVariable("id") Long id) {
log.debug("REST request to delete Tag : {}", id);
tagRepository.deleteById(id);
return ResponseEntity
Expand Down
7 changes: 5 additions & 2 deletions postgres-mvc/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ logging:
level:
root: ERROR
io.netty: ERROR
org.springframework: INFO
org.springframework: DEBUG
liquibase: DEBUG
management:
endpoints:
web:
Expand Down Expand Up @@ -113,7 +114,6 @@ spring:
repositories:
bootstrap-mode: deferred
jpa:
defer-datasource-initialization: true
open-in-view: false
properties:
hibernate.jdbc.time_zone: UTC
Expand Down Expand Up @@ -168,6 +168,9 @@ spring:
client-id: web_app
client-secret: web_app
scope: openid,profile,email
sql:
init:
mode: never

server:
servlet:
Expand Down

0 comments on commit 29500be

Please sign in to comment.