小编Zie*_*zyk的帖子

强制Spring-Boot使用Gson而不是Jackson

Spring-Boot 1.4.2参考声明:

spring.http.converters.preferred-json-mapper = jackson#用于HTTP消息转换的首选JSON映射器.设置为"gson"以强制使用Gson

我们做到了.

  • 我们为preferred-json-mapper设置了gson.
  • 我们已经将Gson添加为我们项目的依赖项.

但仍然使用杰克逊.

最后,我们设法强制Spring-Boot在排除Maven中指向Jackson的所有传递依赖之后使用Gson.

现在的问题是.这是迫使Spring-Boot使用Gson而不是Jackson的唯一方法吗?我们真的需要排除指向杰克逊的所有传递依赖吗?首选的json-mapper设置还不够?

spring-boot

9
推荐指数
2
解决办法
6906
查看次数

Querydsl - 分页功能

似乎在 Jpa QueryDsl 中我可以使用如下分页:

return new JPAQueryFactory(getEntityManager())
    .selectFrom(entity)
    .where(where_clause)
    .orderBy(order_by_clause)
    .offset(pageNumber * 20)
    .limit(20)
    .fetchResults();
Run Code Online (Sandbox Code Playgroud)

问题是:

  • 这是最佳方法吗?fetchResults 是否仅从 DB 加载 20 个元素并进行计数查询以获取有关 db 中实体总数的信息?
  • 或者也许有一些像 .page(2).limit(20) 这样的选项?

是的,我知道 Spring-Data 已经为 QueryDsl 提供了分页和接口,但是由于 Spring-Data 不支持复杂的“order by”子句,我无法使用它:(

querydsl

6
推荐指数
2
解决办法
5157
查看次数

在 spring-security 后面访问 springfox swagger-ui

我将在 Spring Boot (1.4.2v) 中使用带有 swagger-ui 的 springfox (2.6.1v)。

它的配置看起来:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

  @Bean
  public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
               .select()
               .apis(RequestHandlerSelectors.any())
               .paths(PathSelectors.any())
               .build()
               .genericModelSubstitutes(ResponseEntity.class);
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是我的招摇落后于 spring 安全性,我只需要允许管理员访问那里。

问题是允许 swagger-ui 在我的应用程序中工作的匹配器集应该是什么?

public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("??? <<<what_should_be_here>>> ???") // what should be here?
        .hasRole("TENANT_ADMIN");
  }
}
Run Code Online (Sandbox Code Playgroud)

spring-security swagger-ui springfox

6
推荐指数
1
解决办法
6163
查看次数

通过 Rest API 删除客户端

我正在使用:

 <dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-admin-client</artifactId>
    <version>11.0.0</version>
 </dependency>
Run Code Online (Sandbox Code Playgroud)

我想以编程方式删除客户端。

不幸的是,正如我所见,ClientsResource只有keycloak.realm("my-realm").clients()创建选项:

 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 Response create(ClientRepresentation clientRepresentation);
Run Code Online (Sandbox Code Playgroud)

有没有办法使用 REST API 删除客户端?还是故意没有这个选项?

keycloak

2
推荐指数
1
解决办法
1614
查看次数