- 浏览: 2552391 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Spring Boot and RESTful API(15)Logging and Custom SOLR Template
Recently, one of our Spring Boot Project lost the logging in the CloudWatch. I was thinking it is jar conflicts because we bring in a new jar. That mades us dive into the logging for that Project for a while.
First of all, here is the MAVEN command to display the while dependencies which I really think it is useful.
>mvn dependency:tree
I used to use similar command in grails, but this is first time for maven. That is great beginning.
Here is the results how we fix that.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
That is complex because I used to directly use spring boot starter logging, right now It is kind of disable that and enable log4j2 in spring boot. But any way, since it is a quick fix. Make it working first.
In the class path, put log4j.xml there, since we streaming the logging to cloud watch, so we really do not need a File Pending or any other settings, just pending the to console
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR" shutdownHook="disable">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m\r\n%throwable{full}"/>
</Console>
<!--
<Console name="COLOR_CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m}{FATAL=red bright, ERROR=red bright, WARN=red bright, INFO=green bright, DEBUG=green bright, TRACE=blue bright}\r\n%throwable{full}"/>
</Console>
-->
<!--
<File name="FILE" fileName="${sys:java.io.tmpdir}/internal-api.log" append="true">
<PatternLayout>
<pattern>(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m\r\n%throwable{full}</pattern>
</PatternLayout>
</File>
-->
<!--
<Async name="ASYNC_FILE" includeLocation="true">
<AppenderRef ref="FILE"/>
</Async>
-->
</Appenders>
<Loggers>
<Logger name="com.google.inject.internal" level="WARN"/>
<Logger name="com.optimaize" level="WARN"/>
<Logger name="net.sourceforge.cobertura" level="WARN"/>
<Logger name="org.hibernate" level="WARN"/>
<Logger name="com.sillycat" level="INFO" />
<Root level="ALL">
<AppenderRef ref="CONSOLE" level="INFO"/>
<!-- <AppenderRef ref="COLOR_CONSOLE" level="WARN"/> -->
<!-- <AppenderRef ref="FILE" level="ALL"/> -->
<!-- <AppenderRef ref="ASYNC_FILE" level="ALL"/> -->
</Root>
</Loggers>
</Configuration>
Another thing, we do a fix to disable the auto commit on Spring-data-solr, otherwise, our SOLR will have issue to handle 200G Data.
here is the implementation of that idea
package com.sillycat.jobsmonitorapi.repository;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.core.query.SolrDataQuery;
import org.springframework.stereotype.Repository;
@Repository
public class JobCustomRepositorySolrImpl implements JobCustomRepositorySolr
{
private final Logger logger = LoggerFactory.getLogger( this.getClass() );
@Resource
private SolrTemplate solrTemplate;
@Override
public void deleteByCampaignID( Long campaignID, Boolean commit )
{
SolrDataQuery query = new SimpleQuery( new Criteria( "campaign_id" ).is( campaignID ) );
solrTemplate.delete( "job", query );
if ( commit )
{
logger.warn( "Client side should never commit itself." );
solrTemplate.commit( "job" );
}
}
}
References:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
Recently, one of our Spring Boot Project lost the logging in the CloudWatch. I was thinking it is jar conflicts because we bring in a new jar. That mades us dive into the logging for that Project for a while.
First of all, here is the MAVEN command to display the while dependencies which I really think it is useful.
>mvn dependency:tree
I used to use similar command in grails, but this is first time for maven. That is great beginning.
Here is the results how we fix that.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
That is complex because I used to directly use spring boot starter logging, right now It is kind of disable that and enable log4j2 in spring boot. But any way, since it is a quick fix. Make it working first.
In the class path, put log4j.xml there, since we streaming the logging to cloud watch, so we really do not need a File Pending or any other settings, just pending the to console
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR" shutdownHook="disable">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m\r\n%throwable{full}"/>
</Console>
<!--
<Console name="COLOR_CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m}{FATAL=red bright, ERROR=red bright, WARN=red bright, INFO=green bright, DEBUG=green bright, TRACE=blue bright}\r\n%throwable{full}"/>
</Console>
-->
<!--
<File name="FILE" fileName="${sys:java.io.tmpdir}/internal-api.log" append="true">
<PatternLayout>
<pattern>(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m\r\n%throwable{full}</pattern>
</PatternLayout>
</File>
-->
<!--
<Async name="ASYNC_FILE" includeLocation="true">
<AppenderRef ref="FILE"/>
</Async>
-->
</Appenders>
<Loggers>
<Logger name="com.google.inject.internal" level="WARN"/>
<Logger name="com.optimaize" level="WARN"/>
<Logger name="net.sourceforge.cobertura" level="WARN"/>
<Logger name="org.hibernate" level="WARN"/>
<Logger name="com.sillycat" level="INFO" />
<Root level="ALL">
<AppenderRef ref="CONSOLE" level="INFO"/>
<!-- <AppenderRef ref="COLOR_CONSOLE" level="WARN"/> -->
<!-- <AppenderRef ref="FILE" level="ALL"/> -->
<!-- <AppenderRef ref="ASYNC_FILE" level="ALL"/> -->
</Root>
</Loggers>
</Configuration>
Another thing, we do a fix to disable the auto commit on Spring-data-solr, otherwise, our SOLR will have issue to handle 200G Data.
here is the implementation of that idea
package com.sillycat.jobsmonitorapi.repository;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.core.query.SolrDataQuery;
import org.springframework.stereotype.Repository;
@Repository
public class JobCustomRepositorySolrImpl implements JobCustomRepositorySolr
{
private final Logger logger = LoggerFactory.getLogger( this.getClass() );
@Resource
private SolrTemplate solrTemplate;
@Override
public void deleteByCampaignID( Long campaignID, Boolean commit )
{
SolrDataQuery query = new SimpleQuery( new Criteria( "campaign_id" ).is( campaignID ) );
solrTemplate.delete( "job", query );
if ( commit )
{
logger.warn( "Client side should never commit itself." );
solrTemplate.commit( "job" );
}
}
}
References:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
发表评论
-
Update Site will come soon
2021-06-02 04:10 1679I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 316I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 369Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 370Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 455VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 478NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ...
相关推荐
免费的学习视频,比网上骗人那些强多了,希望对大家有帮助。如果没有账号的注册一下就可以了
### Spring Boot开发实战:基于Spring Boot的RESTful API服务的实验心得与案例解析 #### 一、引言 Spring Boot自发布以来,以其强大的自动配置能力、简洁的开发模式以及丰富的社区支持,迅速成为了Java开发者构建...
**Spring Boot RESTful API Demo** 在现代Web开发中,RESTful API已经成为构建可扩展、松耦合服务的主要方式。Spring Boot作为Java生态系统中的一个强大框架,简化了创建生产级的基于Spring的应用程序。本示例将...
3. 接下来,我们需要实现Restful API和WebService API接口,使用Spring Boot的Restful API和CXF框架来实现学生信息的增删改查操作。 4. 最后,我们需要测试Restful API和WebService API接口,确保其正常工作。 结论...
该项目提供基于Java和Spring Boot框架构建的RESTful API设计与调用源码,涵盖17个Java源文件、9个XML配置文件、6个JavaScript文件、4个CSS样式文件、2个HTML文件,共计46个文件。项目旨在实现Spring Boot的API发布与...
为了解决上面这样的问题,本文将介绍RESTful API的重磅好伙伴Swagger2,它可以轻松的整合到Spring Boot中,并与Spring MVC程序配合组织出强大RESTful API文档。它既可以减少我们创建文档的工作量,同时说明内容又...
本文主要介绍了通过使用 Maven Archetype 与 Spring Boot 能够迅速搭建起一个支持CRUD的基本RESTful API项目框架,并提供了从创建初始项目到完成简易数据操作(如增删查)的具体指南和代码样例。 适合具有一定经验但...
内容概要:本文详述了如何利用Spring Boot技术搭建一套简易图书管理系统的RESTful API接口流程,涵盖从初始创建到实现完整CRUD(增删改查)功能的整体步骤,并提供H2内存数据库作为数据存储支持。此外介绍了系统主要...
Spring Boot 整合 Mybatis 实现RESTful API ,具体可以查看博客: http://blog.csdn.net/yaozhiqi1905658804/article/details/70820892
内容概要:详细介绍使用Java、Spring Boot以及相关技术和工具如Maven、H2 database搭建简单的图书管理RESTful API系统全过程,覆盖了从项目的建立、实体类定义、接口编写一直到API的功能测试。项目主要提供了增加、...
在 Spring Boot 中构建 RESTful API,主要涉及以下几个关键知识点: 1. **MVC 模式**:Spring Boot 基于 Spring MVC 框架提供了一种简洁的 Web 开发方式。你可以使用 `@RestController` 注解标记控制器类,而 `@...
而Swagger是目前最流行的接口文档解决方案,本文主要通过代码实战的方式讲解Spring Boot 和Swagger集成生成Restful接口文档。教程参见 http://blog.csdn.net/zjx2016/article/details/74407832
在Spring Boot项目中集成Swagger2,可以帮助我们快速地构建和维护高质量的RESTful API。以下将详细讲解如何利用Spring Boot与Swagger2进行集成,并展示其主要功能和步骤。 **一、集成Swagger2** 1. 添加依赖:首先...
在这个“Spring Boot RESTful 接口示例项目”中,我们可以学习到如何使用 Spring Boot 创建 RESTful 风格的 API。RESTful API 通常通过 HTTP 协议提供服务,利用 GET、POST、PUT、DELETE 等方法操作资源,实现客户端...
基于Spring Boot,采用RESTful风格架构的微信点餐系统源码(高分毕设).zip 基于Spring Boot,采用RESTful风格架构的微信点餐系统源码(高分毕设).zip 基于Spring Boot,采用RESTful风格架构的微信点餐系统源码...
基于 Spring Boot 的 Restful 风格实现增删改查
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,...
Spring Boot实现Restful并对数据库CRUD操作的示例 同时使用了Spring Data JPA,需先创建MySQL数据库名为springbootdb, 数据库表会自动创建(Hibernate开启了ddl-auto:update) 数据库配置参见项目/src/main/...
【Spring Boot 示例代码】是一个专为初学者设计的项目,旨在教授如何利用Spring Boot搭建RESTful API服务。Spring Boot是Spring框架的一个子项目,它简化了配置和启动过程,使得开发者能够快速创建独立运行的Java...