我是骆驼新手。我正在 spring-boot 中做一个项目,使用camel作为路由。我注意到,当我去 SwaggerUi 查看 Post 调用的正确功能时,路由的 contextPath 不起作用:
public void configure() {
restConfiguration().component("servlet").contextPath("service/");
rest("/ocs")
.post("/homologation")
.id(camelRoutesIdConfig.getHomologationRequestRouteId())
.consumes("application/json")
.produces("application/json")
.param()
.name("IntegrationRequestDto")
.type(RestParamType.body)
.required(true)
.description("attivazione nuovo contratto sul portale")
.endParam()
.to("direct:homologation")
}
Run Code Online (Sandbox Code Playgroud)
如果在 application.yml 中我像这样指定 contextPath ,则不会出现此问题:
camel:
rest:
component: servlet
binding-mode: json
enable-cors: true
data-format-property:
prettyPrint: false
component:
servlet:
mapping:
context-path: /service/*
Run Code Online (Sandbox Code Playgroud)
当我在一种情况下拨打 Post 电话时,它可以工作,而在路线中的 ContextPath 情况下,它无法识别该命令并给出
{
"timestamp": "2020-11-22T17:44:26.701+0000",
"status": 404,
"error": "Not Found",
"message": "Not Found",
"path": "/service/ocs/homologation"
}
Run Code Online (Sandbox Code Playgroud)
为什么会出现这个问题呢?为什么我还被迫在 application.yml 中指定,而不是在路由中仅使用一次?感谢大家提供可能的答案
我创建了一个新的反序列化器,以便能够将空字符串写为 null
public class CustomDeserializer extends JsonDeserializer<String> {
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
JsonNode node = jsonParser.readValueAsTree();
if (node.asText().isEmpty()) {
return null;
}
return node.toString();
}
}
Run Code Online (Sandbox Code Playgroud)
尝试在每个用户字段上进行单个注释,自定义工作但通过在整个类上插入注释,我无法再打印 Json 消息
@JsonDeserialize(using = CustomDeserializer.class)
public class User {
private String firstName;
private String lastName;
private String age;
private String address; }
Run Code Online (Sandbox Code Playgroud)
CustomExceptionHandler 向我抛出此错误:Class MethodArgumentNotValidException 这是我的 Kafka Consumer,这是我输入验证注释的唯一一个,但即使删除它也会给我同样的错误
public class KafkaConsumer {
@Autowired
private UserRepository userRepository;
@KafkaListener(topics = "${spring.kafka.topic.name}")
public void listen(@Validated User user) {
User …Run Code Online (Sandbox Code Playgroud) 我是 python 新手,我想从 csv 文件中读取一列值 \xe2\x80\x8b\xe2\x80\x8b 并将它们添加在一起,但仅限于“,”左侧的值\n我的 csv文件:
\nName Code \nAngel 19;90\nEduardo 20;21\nMiguel 30;45 \nRun Code Online (Sandbox Code Playgroud)\n我希望能够仅对“代码”列左侧的数字求和,以便我的输出为“19+20+30 = 69”。\n我尝试删除“;” 并将字符串转换为 int 但求和,但将数字连接在一起,我得到以下输出:
\nYour final sum is : 1990 +2021 +3045 = 7056\nRun Code Online (Sandbox Code Playgroud)\n 我在 Spring Kafka 中有一个小项目,我希望可以从 application.yml 传递我的 kafka 主题并避免硬编码问题。目前我有这样的情况:
public class KafkaConsumer {
@Autowired
private UserRepository userRepository;
@KafkaListener(topics = "myTopic")
public void listen(@Validate UserDto userDto) {
User user= new User(userDto);
userRepository.save(userDto.getAge(), user);
}
}
Run Code Online (Sandbox Code Playgroud)
此时我有静态 kafka 主题(作为字符串)是否可以将其放入 application.yml 并从那里读取它?感谢大家的帮助
java ×2
apache-camel ×1
apache-kafka ×1
dataframe ×1
jackson ×1
json ×1
pandas ×1
python ×1
routes ×1
spring ×1
spring-boot ×1
spring-camel ×1
spring-kafka ×1