小编exp*_*rer的帖子

带有自定义异常类的 Spring REST @ResponseStatus 不会更改返回状态代码

我有一个如下所示的异常类

@ResponseStatus(value=HttpStatus.UNPROCESSABLE_ENTITY, reason="Unprocessable Entity")  // 422
public class UnprocessableEntityException extends RuntimeException {
}
Run Code Online (Sandbox Code Playgroud)

现在状态不会返回为 422,除非我在 Controller 类中编写了一个特定的处理程序,例如:

@ExceptionHandler(UnprocessableEntityException.class)
    @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
    public String handleException(Exception ex) {
...
}
Run Code Online (Sandbox Code Playgroud)

据我了解,我首先不需要@ExceptionHandler,不确定我错过了什么。

spring-rest

7
推荐指数
1
解决办法
6259
查看次数

使用java注释的Spring批处理java.lang.IllegalStateException:无法创建没有元数据的属性

  1. 尝试仅在项目中使用java anotations将FieldSet自动映射到域对象
  2. 失败的原因如下:

    BeanWrapperFieldSetMapper.mapFieldSet (第184行)在以下行(第187行):

    binder.bind(new MutablePropertyValues(getBeanProperties(copy, fs.getProperties())));
    @Override
    public Properties getProperties() {
        if (names == null) {
            throw new IllegalStateException("Cannot create properties without meta data");
        }
    
    Run Code Online (Sandbox Code Playgroud)

    注意:我没有指定名称,因为我正在尝试Automap.

  3. 以下是我的代码:

    @Bean
        public LineMapper<Partner> lineMapper() {
            DefaultLineMapper<Partner> lineMapper = new DefaultLineMapper<Partner>();
            DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
            BeanWrapperFieldSetMapper<Partner> fieldSetMapper = new BeanWrapperFieldSetMapper<Partner>(); 
            fieldSetMapper.setBeanFactory(getApplicationContext()); 
            fieldSetMapper.setTargetType(Partner.class);
            lineMapper.setLineTokenizer(lineTokenizer);
            lineMapper.setFieldSetMapper(fieldSetMapper);
            return lineMapper;
        }
    
    Run Code Online (Sandbox Code Playgroud)
  4. 精确的堆栈跟踪

    退出-DESCR.:org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[class path resource [partner-import.csv]], input=[Mustermann,Max,dahiya.naveen@gmail.com,m]

    引起: java.lang.IllegalStateException: Cannot create properties without meta data at org.springframework.batch.item.file.transform.DefaultFieldSet.getProperties(DefaultFieldSet.java:745)

spring-batch

6
推荐指数
1
解决办法
1708
查看次数

在spring batch itemReader中从流而不是文件中读取

我得到一个csv文件作为webservice调用,需要加密.现在我将它保存在临时目录中,以将其作为setResource提供给Reader.

有没有办法提供流(byte [])而不是先保存文件?

spring-batch

6
推荐指数
1
解决办法
6873
查看次数

@RefreshScope 整个应用程序的替代方案

在使用 spring cloud 配置时,我遇到了 @RefreshScope。

据我了解,@RefreshScope 必须与任何需要动态更新所用属性的 bean 一起使用。

是否有可以在整个应用程序中使用的全局替代方案,而不仅仅是一个 bean?

spring-boot spring-cloud-config

5
推荐指数
0
解决办法
373
查看次数