小编Chr*_*ein的帖子

Spring Boot忽略logback-spring.xml

我有2个使用Logback的Spring Boot(1.4.1-RELEASE)控制台应用程序.两个配置文件或多或少相同,位于my / src/main/resources文件夹中,名为logback-spring.xml.

这两个项目都在其pom.xml中包含maven依赖spring-boot-starter-logging并获取logback Version 1.1.7.

两个poms中定义的Spring Boot配置:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
    <relativePath />
</parent>

<groupId>d.m.v.app-a</groupId>
<artifactId>my-app-a</artifactId>
<version>1.0.16-SNAPSHOT</version>
<packaging>jar</packaging>  

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

但是,在运行应用程序时,其中一个似乎完全忽略了logback配置,而另一个则像预期的那样选择了它.

如果我将文件名更改为无法正常工作的应用程序的logback.xml,它突然正常工作(即使使用我正在使用的弹簧配置文件).

所涉及的任何配置(意味着pom.xml,application.properties等)没有明显差异.

有人知道为什么会这样吗?我发现这种行为相当令人困惑.

java logback maven spring-boot

11
推荐指数
3
解决办法
7666
查看次数

Amazon AWS 客户端因大量请求而超时

我们有一个 Spring Boot 应用程序,可将多媒体文件(最大 100 MB)存储在 S3 兼容的云存储中。应用程序通过 REST 调用或 AMQP 消息代理 (RabbitMQ) 接收这些文件。

通常系统的负载是中等的,所以根本不会有问题。然而,当系统负载较重时,我们会遇到访问 S3 的问题。目前,我们正在通过使用随机分配给调用进程的 10 个 AmazonS3Client 池来解决此问题。这实际上改善了问题,但并没有解决问题。当负载太高(意味着大量的写入和读取操作)时,我们会遇到此类异常:

com.amazonaws.AmazonClientException:无法执行 HTTP 请求:连接超时
    在 com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:299)
    在 com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:170)
    在 com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2648)
    在 com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1049)
    在 com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:924)

我们使用的是 1.3.8 版本的 aws-java-sdk,由于较新版本中的区域设置,无法轻松更新到较新版本。签名算法阻止我们在最新版本中正确访问我们的存储桶。

实现如下:

初始化(在构造函数级别):

ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionTimeout(AWS_CONNECTION_TIMEOUT);
clientConfiguration.setMaxConnections(AWS_MAX_CONNECTIONS);
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

for (int i = 0; i < AWS_MAX_CLIENTS; i++) {
     s3[i] = new AmazonS3Client(credentials, clientConfiguration);
     s3[i].setEndpoint(endpoint);       
}
Run Code Online (Sandbox Code Playgroud)

放:

int i = getRandomClient();
s3[i].putObject(bucketName, key, file);
Run Code Online (Sandbox Code Playgroud)

得到:

ReadableByteChannel …
Run Code Online (Sandbox Code Playgroud)

java amazon-s3 spring-boot aws-sdk

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

rabbitmq 的 Spring Boot 可信包

我们正在构建一个通过 RabbitMQ 接收消息的 Spring Boot 应用程序 (2.0.4-RELEASE)。因此application.properties包含与兔子相关的配置:

spring.rabbitmq.addresses=****
spring.rabbitmq.username=****
spring.rabbitmq.password=****
spring.rabbitmq.listener.simple.concurrency=2
spring.rabbitmq.listener.simple.prefetch=5
spring.rabbitmq.listener.simple.retry.enabled=true
spring.rabbitmq.listener.simple.retry.max-attempts=5
Run Code Online (Sandbox Code Playgroud)

配置:

@Bean
public TopicExchange fileUpdate() {
    return new TopicExchange("my.fancy.exchange", true, false);
}

@Bean
public Queue fileUpload() {
    return new Queue("myFancyQueue", true);
}

@Bean
public Binding bindingUpload(Queue queue, TopicExchange eventExchange) {
    return BindingBuilder.bind(queue).to(eventExchange).with("");
}
Run Code Online (Sandbox Code Playgroud)

消息消费者:

@RabbitListener(queues = "myFancyQueue")
public void receive(Object message) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

当接收到特定类型的消息(例如__TypeId__: my.fancy.package.Clazz)时,会抛出以下错误:

引起原因:java.lang.IllegalArgumentException:类“my.fancy.package.Clazz”不在受信任的包中:[java.util,java.lang]。如果您认为反序列化此类是安全的,请提供其名称。如果序列化仅由可信来源完成,您还可以启用全部信任 (*)。

据我所知,到目前为止,activeMQ 通过application.propertiesas提供了一个配置选项

spring.activemq.packages.trust-all=
Run Code Online (Sandbox Code Playgroud)

或者

spring.activemq.packages.trusted=
Run Code Online (Sandbox Code Playgroud)

但我找不到任何适用于rabbitMQ的类似选项。到目前为止,我一直在使用一种解决方法来解决我的问题,但当然,如果在配置文件中拥有这样的选项那就太好了。

到目前为止我的解决方案:

添加配置类:

@Bean
public MessageConverter jsonMessageConverter() …
Run Code Online (Sandbox Code Playgroud)

java spring rabbitmq spring-boot

4
推荐指数
1
解决办法
2940
查看次数

标签 统计

java ×3

spring-boot ×3

amazon-s3 ×1

aws-sdk ×1

logback ×1

maven ×1

rabbitmq ×1

spring ×1