- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我创建了:https://jira.spring.io/browse/BATCH-2778
我正在开发 Spring Batch + Redis (Spring Data Redis) 示例。在这个例子中,我正在阅读 student.csv
文件并将所有数据按原样存储在 Redis 数据库中。我想用 dateOfBirth
作为Date
我确定我需要进行一些日期逻辑转换以将值 Date 存储在 Redis
中.
根据我的分析,我似乎无法使用 @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
,因为我根本不处理 JSON。我想我应该使用转换器等来转换 Byte[]
至 Date
和 Date
至 Byte[]
等等
事实上,我尝试了这些选项,但没有用。有任何快速帮助吗?
注意:我不想将 dateOfBirth 保存为字符串值。
org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 2 in resource=[URL [file:c:/Videos/student.csv]], input=[1,John,Doe,05-12-1988 12:34:45]
at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:184) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:89) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader$$FastClassBySpringCGLIB$$ebb633d0.invoke(<generated>) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136) ~[spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) [spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.batch.item.file.FlatFileItemReader$$EnhancerBySpringCGLIB$$87932856.read(<generated>) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:394) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:308) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:141) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:134) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_162]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_162]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_162]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) [spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197) [spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) [spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) [spring-aop-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at com.sun.proxy.$Proxy69.run(Unknown Source) [na:na]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:163) [spring-boot-autoconfigure-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:179) [spring-boot-autoconfigure-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:134) [spring-boot-autoconfigure-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:128) [spring-boot-autoconfigure-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:792) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at com.myexample.DateBatchPocApplication.main(DateBatchPocApplication.java:12) [classes/:na]
Caused by: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'target' on field 'dateOfBirth': rejected value [05-12-1988 12:34:45]; codes [typeMismatch.target.dateOfBirth,typeMismatch.dateOfBirth,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [target.dateOfBirth,dateOfBirth]; arguments []; default message [dateOfBirth]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'dateOfBirth'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Date' for property 'dateOfBirth': no matching editors or conversion strategy found]
at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.mapFieldSet(BeanWrapperFieldSetMapper.java:200) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:43) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:180) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
... 56 common frames omitted
StudentJob.java
@Configuration
public class StudentJob {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Autowired
private FlatFileItemReader<Student> studentReader;
@Autowired
private StudentWritter studentWritter;
@Bean
public Job readstudentCSVFileJob() {
return jobBuilderFactory.get("readstudentCSVFileJob").incrementer(new RunIdIncrementer())
.start(countryCurrStepOne()).build();
}
@Bean
public Step countryCurrStepOne() {
return stepBuilderFactory.get("studentStepOne").<Student, Student>chunk(5).reader(studentReader)
.writer(studentWritter).build();
}
}
StudentBatchConfig.java
@Slf4j
@Configuration
public class StudentBatchConfig {
@Bean(destroyMethod="")
@StepScope
public FlatFileItemReader<Student> studentReader(@Value("${input.student.path}") Resource resource) throws IOException {
log.debug("Resource Path : "+resource.getFile());
FlatFileItemReader<Student> itemReader = new FlatFileItemReader<>();
itemReader.setName("STUDENT_READER");
itemReader.setResource(resource);
itemReader.setLineMapper(studentlineMapper());
itemReader.setLinesToSkip(1);
return itemReader;
}
@Bean
public LineMapper<Student> studentlineMapper() {
// Delimited Line Tokenizer
DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
lineTokenizer.setNames("id", "firstName", "lastName", "dateOfBirth");
lineTokenizer.setIncludedFields(new int[] {0,1,2,3});
// Bean Wrapper Field SetMapper
BeanWrapperFieldSetMapper<Student> fieldSetMapper = new BeanWrapperFieldSetMapper<>();
fieldSetMapper.setTargetType(Student.class);
DefaultLineMapper<Student> lineMapper = new DefaultLineMapper<>();
lineMapper.setLineTokenizer(lineTokenizer);
lineMapper.setFieldSetMapper(fieldSetMapper);
return lineMapper;
}
@Bean
public StudentWritter studentWritter() {
return new StudentWritter();
}
}
StudentWritter.java
public class StudentWritter implements ItemWriter<Student>{
@Autowired
private StudentRepository studentRepository;
@Override
public void write(List<? extends Student> students) throws Exception {
studentRepository.saveAll(students);
}
}
EDIT-1:
@Slf4j
@Configuration
public class StudentBatchConfig {
private static final SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm");
@Bean(destroyMethod="")
@StepScope
public FlatFileItemReader<Student> countryReader(@Value("${input.student.path}") Resource resource) throws IOException {
log.debug("Resource Path : "+resource.getFile());
FlatFileItemReader<Student> itemReader = new FlatFileItemReader<>();
itemReader.setName("STUDENT_READER");
itemReader.setResource(resource);
itemReader.setLineMapper(studentLineMapper());
itemReader.setLinesToSkip(1);
return itemReader;
}
@SuppressWarnings("rawtypes")
@Bean
public LineMapper<Student> studentLineMapper() {
DefaultLineMapper<Student> lineMapper = new DefaultLineMapper<>();
// Delimited Line Tokenizer
DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
lineTokenizer.setNames("id", "firstName", "lastName", "dateOfBirth");
lineTokenizer.setIncludedFields(new int[] {0,1,2,3});
// Date parsing logic has been added
CustomDateEditor customDateEditor = new CustomDateEditor(format, false);
HashMap<Class, PropertyEditor> customEditors = new HashMap<>();
customEditors.put(Date.class, customDateEditor);
// Bean Wrapper Field SetMapper
BeanWrapperFieldSetMapper<Student> fieldSetMapper = new BeanWrapperFieldSetMapper<>();
fieldSetMapper.setTargetType(Student.class);
fieldSetMapper.setCustomEditors(customEditors);
lineMapper.setLineTokenizer(lineTokenizer);
lineMapper.setFieldSetMapper(fieldSetMapper);
return lineMapper;
}
@Bean
public StudentWritter studentWritter() {
return new StudentWritter();
}
}
学生.java
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("student")
public class Student {
@Id @Indexed
private String id;
private String firstName;
private String lastName;
private Date dateOfBirth;
}
但日期存储不正确..似乎是格式问题..
注意:如果我在 Microsoft 的 CSV 编辑器中打开此文件,它会显示 dd-MM-yyyy HH:mm
但是如果我在 Notepad++ 中编辑这个文件,那么它会显示
id,firstName,lastName,dateOfBirth
1,John,Doe,25-11-2018 14:48:10
2,Sameer,Kumbhare,25-11-2018 14:48:10
最佳答案
您的问题与 JSON 无关,根据堆栈跟踪,问题是 BeanWrapperFieldSetMapper
不知道如何转换 05-12-1988 12:34:45
到 java.util.Date
。您需要像这样使用自定义日期编辑器对其进行配置:
CustomDateEditor customDateEditor = new CustomDateEditor(/* your DateFormat here */);
HashMap<Class, PropertyEditor> customEditors = new HashMap<>();
customEditors.put(Date.class, customDateEditor);
fieldSetMapper.setCustomEditors(customEditors);
CustomDateEditor
来自 Spring 框架:org.springframework.beans.propertyeditors.CustomDateEditor
。
希望这对您有所帮助。
关于spring - 字段 'target' 上的对象 '' 中的字段错误 : rejected value []; codes [typeMismatch. 目标.,typeMismatch.,typeMismatch.java.util.Date,typeMismatch],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53615922/
我一直在努力理解下面两个的区别,哪个是空闲的使用方式: let getClient = () => { return connect() .then((client) => {
我正在学习一门关于 JavaScript 函数式编程的很棒的在线类(class)。在讲师使用 Array.prototype.reject() 并且它在运行时对我不起作用之前,我一直很好。 我想使用“
这个问题在这里已经有了答案: Do I need to return after early resolve/reject? (6 个答案) 关闭 6 年前。 我是 Promise 的新手,我想知道
我对 Angular JS deferred 和 $q 感到困惑。我找到了这个 SO Question这解释了 $q.defer() 和 $q 之间的区别。它解释了 $q.reject is a sh
我正在尝试处理 Angular $q 服务及其相关对象和 API。当我查看控制台中的对象时,我看到: var deferred = $q.defer() ...(and then from conso
我在运行测试时遇到问题(在 Node 中), 我正在模拟一个被拒绝的 promise ,我的代码应该重试(使用 promise-retry 如果可能相关的话)。 当我使用 stub.returns(P
当我编译或运行它时,程序会显示正确的信息。问题是当我检查程序时。它显示“:(拒绝”“分钟检查我的时等待输入被拒绝时超时”程序。我也尝试使用 GetInt 和 get_int 。你能帮助我吗,请? in
对于 Ruby 中的 Hash,reject! 和 reject 与 delete_if 有何不同?谁能用简单的代码片段解释它们之间的区别? 最佳答案 由于其他答案指的是 Array#delete_i
当我尝试使用 Firestore 获取数据时,出现上述错误 - 我正在尝试从数据库检索 token ,以便可以发送消息: exports.getUsers = functions.https.onRe
这个问题在这里已经有了答案: Are JavaScript forever-pending promises bad? (2 个答案) 关闭 4 年前。 问题是这样的 function demo()
您好,我正在尝试调用返回 promise 的异步函数 makeRemoteExecutableSchema。 async function run() { const schema = await
我发出的每个 http 请求似乎都会出现此错误。我不太确定它来自哪里? (node:39390) UnhandledPromiseRejectionWarning:未处理的 promise 拒绝(拒绝
我的代码运行良好,但今天运行时发生了这种情况: (node:8592) UnhandledPromiseRejectionWarning: Unhandled promise rejection (r
我正在尝试从 mlabs 连接 mongodb。我插入了以下代码: Mongoose.connect('mongodb://:@ds163402.mlab.com:63402/projecttwist
我已将 Cucumber 与 nightwatch.js 集成。 我的 package.json 看起来像:- { "name": "learning-nightwatch", "versio
目前,我在“Javascript”代码中遇到了 promise 问题。它不断抛出“TypeError: res.status(...).json(...).catch is not a functio
首先,请看这个demo。 function loadImageAsync(url) { return new Promise(function(resolve, reject) { var
我已经在这个问题上工作了很长时间,但我无法真正解决它。当我执行 ionic Cordova build android 时,它运行良好,直到它到达 Cordova build android,任何人都
不知道是什么导致了这个问题。昨天它运行良好。今天,当我尝试运行 react-native run-android 时。我收到这个错误。有任何想法吗? Starting JS server... Run
我是第一次使用.then,而不是.then我使用回调函数。 下面是我的代码片段: phantom.create().then(function (ph) { ph.createPage().t
我是一名优秀的程序员,十分优秀!