小编spr*_*ner的帖子

ByteArray资源使用

我有一个 pdf 模板,它存储在物理路径或应用程序类路径中。我必须阅读此模板并根据每个请求的用户输入填写每个请求的字段。我想将此文件转换为字节并在应用程序启动期间将其存储在配置 bean 中,而不是每次都读取模板文件。为此,我可以在 Spring 中使用 ByteArrayResource 或其他更好的方法。

我的目标不是每次都读取模板文件。

java spring-boot

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

如何在Spring Boot应用程序中动态更改logback日志级别

我有一个 Spring boot 应用程序,它使用 logback.xml 进行日志记录配置。我正在寻找动态更改日志级别的选项。例如,如果我部署了一个日志级别为 ERROR 的应用程序,假设我想将其更改为 INFO,但我不想重新部署/重新启动我的 JVM。

我们是否有可能像配置服务器一样配置 logback.xml 来实现这一点

logback spring-boot spring-cloud

5
推荐指数
1
解决办法
8426
查看次数

我们可以在同一个应用程序中同时使用 MongoRepository 和 MongoTemplate

我需要在 MongoDB 上编写一些复杂的查询和一些简单的查询。我可以将 MongoRepository 用于简单查询,将 MongoTemplate 与 Query 或 Criteria 一起用于复杂查询实现相同的应用程序。

在相同的应用程序中同时使用 MongoTemplate 和 MongoRepositories 是否是好的设计。这种方法有什么缺点吗。

还有什么是编写包含大量谓词的复杂查询的最佳方法,这些谓词涉及和,或,IN 和 Not In 在单个查询中。

spring-data mongodb-query spring-data-mongodb

5
推荐指数
1
解决办法
2939
查看次数

如何在Spring Boot中使用@Bean创建或配置Rest模板

我想在Spring Boot应用程序的配置类中RestTemplate使用@Bean注释定义为应用程序bean 。

我在应用程序流程中的不同位置调用了4个REST服务。目前,我RestTemplate每次创建每个请求。有没有一种方法可以将其定义为application bean using @Bean并使用using 注入@Autowired

这个问题的主要原因是我可以定义RestTemplateusing,@Bean但是当我注入它时,我将@Autowired失去所有定义的拦截器(拦截器不会被调用。)

配置类别

@Bean(name = "appRestClient")
public RestTemplate getRestClient() {

    RestTemplate  restClient = new RestTemplate(
        new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));

    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
    interceptors.add(new RestServiceLoggingInterceptor());
    restClient.setInterceptors(interceptors);

    return restClient;
}
Run Code Online (Sandbox Code Playgroud)

服务等级

public class MyServiceClass {

    @Autowired
    private RestTemplate appRestClient;

    public String callRestService() {
        // create uri, method response objects
        String restResp = appRestClient.getForObject(uri, method, response);
        // do something with …
Run Code Online (Sandbox Code Playgroud)

spring-boot

3
推荐指数
3
解决办法
2万
查看次数

Liberty Core,Liberty Base,Liberty Network Deployment版本有什么区别?

是否有任何文档提供有关Liberty Core,Liberty Base,Liberty Network Deployment版本之间差异的信息?

我想使用Liberty并在Docker数据中心部署我的应用程序.但我不确定应该使用哪个版本的Liberty.这些版本之间的主要区别是什么?我的应用程序将具有不同的技术堆栈,如REST,SOAP,EJB,RPC,缓存,JPA等.

websphere-liberty

3
推荐指数
1
解决办法
4103
查看次数

如何在 Spring Boot 中忽略 Post 请求正文中的空值

我正在使用 POST 动词调用 REST 服务。发布请求正文是动态构造的。在某些情况下,很少有字段会填充空值。即使我使用我的请求 pojo@JsonInclude(Include.NON_NULL)@JsonInclude(JsonInclude.Include.NON_NULL)空值字段也不会被删除。

我的示例请求如下所示。

我自己构建 requestEntity 而不是在发布之前解析它。

resetTemplate.exchange(uri,HTTP.POST,requestEntity,responseObject)
Run Code Online (Sandbox Code Playgroud)

如何在具有空值的请求正文文件中移除

我使用的是Spring Boot 1.5.9,它使用的是Jackson 2.x

spring-mvc spring-boot

3
推荐指数
1
解决办法
6998
查看次数