我想使用@Retryable注释restTemplate.我已经添加:
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
以及@EnableRetry配置类.我标记了方法:
restTemplate.exchange(url, HttpMethod.POST, request, String.class);
Run Code Online (Sandbox Code Playgroud)
用(在一个新的主题中)
@Retryable(maxAttempts=4,value=Exception.class,backoff=@Backoff(delay = 2000))
Run Code Online (Sandbox Code Playgroud)
但我从catalina得到错误:
27-Oct-2017 18:11:41.023 SEVERE [http-nio-8080-exec-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
at
<ommitted>
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is …Run Code Online (Sandbox Code Playgroud) 我有一个JSON这样的文件:
{
"objects": [{
"type": "FirstType",
(...)
"details": {
"id": 1,
"name": "FirstElementOfTheFirstType",
"font": "18px arial"
},
"id": "18e"
},
(...)
{
"type": "SecondType",
(...)
"details": {
"id": 1,
"name": "FirstElementOfTheSecondType",
"font": "18px arial"
},
"id": "18f"
}
],
"background": "#ffffff"
}
Run Code Online (Sandbox Code Playgroud)
我的目标是删除 Fe中某个type和 的节点,如果我想删除命名和的元素。我会得到:iddetailstypeFirstTypeid1
{
"objects": [
(...)
{
"type": "SecondType",
(...)
"details": {
"id": 1,
"name": "FirstElementOfTheSecondType",
"font": "18px arial"
},
"id": "18f"
}
],
"background": "#ffffff"
} …Run Code Online (Sandbox Code Playgroud) 问题在于,@AfterMapping根本没有调用带有注释的方法。从testToEntityMapping它转到toEntity方法,但它不调用任何toEntityAfterMapping()方法。为什么 ?是否可以 ?我如何使用 MapStruct 实现这一目标?
(这里我准备了一个没有意义的场景,但它完全抓住了我的问题的本质)
实体:
public class Ford {
private String color;
private String market;
private int totalWidth;
//getters and setters omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)
托斯:
public abstract class FordDto {
public String market;
public String color;
//getters and setters omitted for brevity
}
public class EuropeanFordDto extends FordDto{
private int totalWidth;
public int getTotalWidth() {
return totalWidth + 2;//"+2" for EU market
}
//setter omitted for brevity
}
public …Run Code Online (Sandbox Code Playgroud) 我有一个这样的列表jsoup:
Elements tbody = new Elements();
Run Code Online (Sandbox Code Playgroud)
tbody可能看起来像这样(----分隔tbody列表中的元素):
<td>
<div data-emission="56b2140adb6da7bf3cbf6228" class="mainCell">
<a href="/tv/weather-country-12457/"> <span class="left">16:00</span>
<div>
<p>Weather - country</p>
</div> </a>
</div>
<div data-emission="56b2140adb6da7bf3cbf6237" class="mainCell shows pending">
<a href="/shows/that's-70-show-550347/epi1201/"> <span class="left">16:10</span>
<div>
<p>That's 70 show</p>
<span class="info">epi.?1201, Show</span>
</div> <p class="onAir"> <span>Pending</span> <u></u> <u style="width: 5%"></u> </p> </a>
</div> </td>
---------------------------------------------------------------------------
<td>
<div data-emission="56b23876db6da7bf3cbf6588" class="mainCell pending">
<a href="/tv/weather-563806/"> <span class="left">16:10</span>
<div>
<p>Weather</p>
</div> <p class="onAir"> <span>Pending</span> <u></u> <u style="width: 51%"></u> </p> </a>
</div> …Run Code Online (Sandbox Code Playgroud) 我有这样的事情:
Integer totalIncome = carDealer.getBrands().stream().mapToInt(brand -> brand.getManufacturer().getIncome()).sum();
Integer totalOutcome = carDealer.getBrands().stream().mapToInt(brand -> brand.getManufacturer().getOutcome()).sum();
Run Code Online (Sandbox Code Playgroud)
我怎么能在一个流中写出来?Pair<Integer, Integer>用totalIncome和收集fe totalOutcome?
编辑:
谢谢你们的评论,答案和参与.我会对使用流来解决该问题的不同方法提出疑问.你怎么看待这个:
final IncomeAndOutcome incomeAndOutcome = carDealer.getBrands()
.stream()
.map(Brand::getManufacturer)
.map(IncomeAndOutcome::of)
.reduce(IncomeAndOutcome.ZERO, IncomeAndOutcome::sum);
static class IncomeAndOutcome {
private static final IncomeAndOutcome ZERO = of(0, 0);
@Getter
private final int income;
@Getter
private final int outcome;
public static IncomeAndOutcome of(final int income, final int outcome) {
return new IncomeAndOutcome(income, outcome);
}
public static IncomeAndOutcome of(final Manufacturer manufacturer) {
return new …Run Code Online (Sandbox Code Playgroud) 我想在UserDTO和之间映射User,但要排除一个字段city。我该怎么做,因为虽然这种方法行得通,但它不能:
ModelMapper modelMapper = new ModelMapper();
modelMapper.typeMap(UserDTO.class,User.class).addMappings(mp -> {
mp.skip(User::setCity);
});
Run Code Online (Sandbox Code Playgroud) 在mapstruct 中,1.3.0.Final我们通过构造函数进行依赖注入。文档说:
生成的映射器将注入uses 属性中定义的所有类
(...)
对于抽象类或装饰器,应使用 setter 注入。
我有以下示例:
@Mapper
public abstract class VehicleMapper {
@Autowired
private CarMapper carMapper;
@Autowired
private BikeMapper bikeMapper;
@Override
public VehicleDTO toDto(final Vehicle source) {
if (source instanceof Car) {
return carMapper.toDto((Car) source);
} else if (source instanceof Bike) {
return bikeMapper.toDto((Bike) source);
} else {
throw new IllegalArgumentException();
}
}
(...)
Run Code Online (Sandbox Code Playgroud)
所以在我的例子中它应该看起来像这样(componentModel在maven中定义):
@Mapper
public abstract class VehicleMapper {
private CarMapper carMapper;
private BikeMapper bikeMapper;
@Autowired
public void setCarMapper(final CarMapper carMapper) …Run Code Online (Sandbox Code Playgroud) 我的问题几乎是1:1的这一个。我唯一的区别(和挣扎)是我的“数据容器”有一组对象。它看起来像这样:
public class A {
int plainFieldA;
B fieldB;
List<B> collectionB = new ArrayList<>();
}
public class B {
int plainFieldB;
}
@Transactional(readOnly = true)
@GetMapping("")
public Entity getAll(A reqParam) {
return getAll(reqParam);
}
Run Code Online (Sandbox Code Playgroud)
是否可以collectionB在http://localhost/api/test?plainFieldA=1不创建转换器的情况下定义url 的参数?@GameSalutes 正确地指出,从 spring 开始4我们可以这样fieldB.plainFieldB=2做,url 将是:http://localhost/api/test?plainFieldA=1&fieldB.plainFieldB=2但问题是我们可以在collectionB不创建转换器的情况下做类似的事情吗?
我有以下类结构(给出的示例毫无意义,我只是为了问题目的而制作的):
public class ManufacturerDto {
private String name;
private Boolean withConfirmation;
//getters and setters omitted for brevity
}
public class CarDto {
private ManufacturerDto manufacturer;
//getters and setters omitted for brevity
}
public abstract class VehicleDto {
private list<CarDto> cars = new ArrayList<>();
//getters and setters omitted for brevity
}
public class EuropeanMarketCarDto extends VehicleDto {
public Map<String, List<CarDto>> getCarManufacturerToCarsMap() {
return this.getCarDtos()
.stream()
.collect(Collectors.groupingBy(e -> e.manufacturer().getName()));
//getters and setters omitted for brevity
}
}
Run Code Online (Sandbox Code Playgroud)
在给定的场景中,groupingBy返回几乎我想要的所有内容,但我的密钥有问题。在getCarManufacturerToCarsMap()方法中,我希望有一个 …
我在 Windows 上使用 docker - 版本18.03(客户端)/ 18.05(服务器)。我已经docker-compose为 ELK 堆栈创建了文件。一切正常。我想做的是,logtrail在 kibana 启动之前安装。我想logtrail*.zip先复制,然后调用安装:
container_name: kibana
(...)
command:
- docker cp kibana:/ ./kibana/logtrail/logtrail-6.7.1-0.1.31.zip
- /bin/bash
- ./bin/kibana-plugin install/logtrail-6.7.1-0.1.31.zip
Run Code Online (Sandbox Code Playgroud)
但这看起来不像是正确的方式,因为首先它不起作用,其次我不确定我是否可以像我一样调用多个命令,第三我不确定是否允许docker cpincommand服务创建的那个阶段
private static <K, V extends Comparable<? super V>> Map<K, V>
sortByValue( Map<K, V> map )
{
Map<K, V> result = new LinkedHashMap<>();
Stream<Map.Entry<K, V>> st = map.entrySet().stream();
st.sorted( Map.Entry.comparingByValue() )
.forEachOrdered( e -> result.put(e.getKey(), e.getValue()) );
return result;
}
Run Code Online (Sandbox Code Playgroud)
这是这篇文章的一个例子.有用.问题是它按升序排序.如何将其更改为降序?
我可以这样做:
public static <K, V extends Comparable<? super V>> Map<K, V>
sortByValue( Map<K, V> map )
{
List<Map.Entry<K, V>> list =
new LinkedList<Map.Entry<K, V>>( map.entrySet() );
Collections.sort( list, new Comparator<Map.Entry<K, V>>()
{
public int compare( Map.Entry<K, V> o1, …Run Code Online (Sandbox Code Playgroud) 我有一个Windows服务的问题.
protected override void OnStart(string[] args)
{
while (!File.Exists(@"C:\\Users\\john\\logOn\\oauth_url.txt"))
{
Thread.Sleep(1000);
}
...
Run Code Online (Sandbox Code Playgroud)
我必须等待一个特定的文件,因此while循环是必要的,但服务将无法像这样循环启动.我可以做什么来运行正在运行的服务和检查文件是否存在的机制?
java ×7
java-8 ×2
java-stream ×2
mapstruct ×2
spring ×2
spring-boot ×2
c# ×1
dictionary ×1
docker ×1
json ×1
jsonpath ×1
jsoup ×1
modelmapper ×1
sorting ×1
spring-retry ×1