我有一个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) <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) 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)