小编dam*_*ros的帖子

接收错误即使定义了自定义@ControllerAdvice,也无法调用@ExceptionHandler

我有一个Spring 4.1.6的应用程序,我创建了一个用于处理所有异常的类,如下所示:

@ControllerAdvice
public class RestControllerAdvice {
...
@ExceptionHandler({Exception.class})
public ResponseEntity<Result> handleException(final Exception ex) {
    Result res = new Result();
    try {
        Exception root = (Exception) ExceptionUtils.getRootCause(ex);
        if (root == null) {
            root = ex;
        }
        if (root instanceof BindException) {
            handleBindException(root, res);
        } else if (root instanceof ConstraintViolationException) {
            handleConstraintViolations(root, res);
        } else if (root instanceof NoHandlerFoundException) {
            handleNoHandlerFoundException(root, res);
        } else {
            logError(res, ex);
        }
    } catch (Exception e) {
        logError(res, e);
    } finally {
        if (!res.hasErrors()) { …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

10
推荐指数
1
解决办法
1万
查看次数

错误消息:“项目构建错误:不可解析的 POM

<project >xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.cucumber</groupId>
    <artifactId>MavenCucumberPrototype</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>MavenCucumberPrototype</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
        </dependency>
        </dependencies>
        </project>
Run Code Online (Sandbox Code Playgroud)

java maven

4
推荐指数
2
解决办法
4万
查看次数

How to get values of nested class attribute using reflection?

Currently I have classes with several nested classes inside is, like:

public class Foo {

  private Bar bar;

  //getter & setter

  public class Bar {

    private Abc abc;

    //getter & setter

    public class Abc {
      @RequiredParam
      private String property;

      //getter & setter
    }
  }

}
Run Code Online (Sandbox Code Playgroud)

I am trying to get the value of the fields but I am having a hard time how to achieve this.

So far I have:

  public static boolean isValid(Object paramClazz) throws Exception {
    List<Class> classes …
Run Code Online (Sandbox Code Playgroud)

java reflection

3
推荐指数
1
解决办法
4107
查看次数

标签 统计

java ×3

maven ×1

reflection ×1

spring ×1

spring-mvc ×1