我在Spring Batch中创建异步处理器时遇到问题.我的处理器越来越ID从reader基于从响应,建立对象SOAP调用.有时为1输入(ID)必须有例如60-100个SOAP调用,有时只有1个.我试图制作多线程步骤,它正在处理例如50个输入,但它没用,因为49个线程在1秒内完成了它们的工作并被阻止,等待这个正在进行60-100次SOAP通话的人.现在我用AsyncItemProcessor+ AsyncItemWriter但这个解决方案对我来说很慢.由于我的输入(IDs)很大,从DB读取的大约25k项目我希望在时间开始~50-100输入.
这是我的配置:
@Configuration
public class BatchConfig {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
private DatabaseConfig databaseConfig;
@Value(value = "classpath:Categories.txt")
private Resource categories;
@Bean
public Job processJob() throws Exception {
return jobBuilderFactory.get("processJob").incrementer(new RunIdIncrementer()).listener(listener()).flow(orderStep1()).end().build();
}
@Bean
public Step orderStep1() throws Exception {
return stepBuilderFactory.get("orderStep1").<Category, CategoryDailyResult>chunk(1).reader(reader()).processor(asyncItemProcessor()).writer(asyncItemWriter()).taskExecutor(taskExecutor()).build();
}
@Bean
public JobExecutionListener listener() {
return new JobCompletionListener();
}
@Bean
public ItemWriter asyncItemWriter() { …Run Code Online (Sandbox Code Playgroud) 我有一个关于Spring + Thymeleaf日期格式的问题.我有一个简单的实体与LocalDate date字段.我希望从表单中的用户获取此日期并将其保存到MySQL数据库.我收到这样的错误:
无法将类型为java.lang.String的属性值转换为属性日期所需的类型java.time.LocalDate; 嵌套异常是org.springframework.core.convert.ConversionFailedException:无法从类型java.lang.String转换为类型java.time.LocalDate,值为2019-04-30; 嵌套异常是java.time.format.DateTimeParseException:无法在索引2处解析文本2019-04-30
我的实体:
@Entity
@Table(name="game")
public class Game{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Transient
private User gameOwner;
private LocalDate date;
private LocalTime time;
//other fields
Run Code Online (Sandbox Code Playgroud)
Thymeleaf观点/形式:
<form action="#" th:action="@{/games/addForm}" th:object="${gameForm}" method="post">
<p>Date: <input type="date" th:field="*{date}" /></p>
</form>
Run Code Online (Sandbox Code Playgroud)
这个问题的原因是什么?也许还有其他更好的存储日期方式?
在春天,是否有可能例如。POST单个对象到控制器@RequestBody?像这样的东西:
@RequestMapping(value = "/users", method = RequestMethod.POST)
public ResponseEntity<Void> createUser(@RequestBody Long userId) {
// do smth with userId
}
Run Code Online (Sandbox Code Playgroud)
如果是,json身体应该是什么样子?
在Spring Boot Web应用程序中,User想要重置密码,因此他进入Reset password页面.现在我想让他输入他的电子邮件地址,推送Reset,我想重定向myapp/resetPassword?email=HIS_EMAIL到处理密码重置.
我的代码:
@RequestMapping(value = "/resetPassword", method = RequestMethod.GET)
public String resetPasswordForm(Model model){
model.addAttribute("email", new String());
return "resetPassword";
}
@RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
public String resetPassword(@RequestParam("email") String email) {
User user = userService.findUserByEmail(email);
//playing with logic
return "redirect:/";
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能在我的百里叶页面上实现它?我试过这样的事情:
<form th:action="@{/resetPassword(email=${email})}" method="post">
<input type="email" th:field="${email}" th:placeholder="Email" />
<div class="clearfix">
<button type="submit">Reset</button>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
不幸的是我email的总是空的.有人可以帮忙吗?
spring ×4
java ×2
thymeleaf ×2
hibernate ×1
json ×1
mysql ×1
rest ×1
spring-batch ×1
spring-mvc ×1