Skip to content

Instantly share code, notes, and snippets.

@SimpleChenyh
SimpleChenyh / CloudEnvironment.java
Created Aug 14, 2018
非Springboot项目从config-server读取配置文件
View CloudEnvironment.java
public class CloudEnvironment extends StandardServletEnvironment {
static Logger logger = LoggerFactory.getLogger(CloudEnvironment.class);
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
super.customizePropertySources(propertySources);
try {
//用来添加应用名到environment中
propertySources.addLast(initResourcePropertySourceLocator("cloud-config-context.properties"));
@SimpleChenyh
SimpleChenyh / CacheConfiguration
Created Jun 9, 2019
Spring boot with caffeine cache
View CacheConfiguration
@Bean
public CaffeineCacheManager writeCacheHalfMinute() {
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(CacheNames.Write.HALF_MINUTE);
caffeineCacheManager.setCaffeine(Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.SECONDS)
.maximumSize(100));
return caffeineCacheManager;
}
@SimpleChenyh
SimpleChenyh / CaffeineCacheController
Created Jun 9, 2019
Use Caffeine cache in controller
View CaffeineCacheController
@GetMapping("create")
@Cacheable(value = CacheNames.Write.HALF_MINUTE, key = "#p0", cacheManager = "writeCacheHalfMinute")
public String test1(@RequestParam String user) throws InterruptedException {
log.error(user);
Thread.sleep(3000);
return "1111111111";
}
@SimpleChenyh
SimpleChenyh / CustomNullSerializer
Created Dec 1, 2019
Jackson return empty instead of null
View CustomNullSerializer
package xx.xx;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import java.io.IOException;
import java.util.List;
You can’t perform that action at this time.