使用Spring MVC 4,当我将Spring Security 3.2添加到pom时,我得到ASM ClassReader无法解析类文件错误

时间:2014-10-08 11:30:13

标签: eclipse spring-mvc spring-security java-8

我在eclipse中使用Java 8。问题可能是Spring安全性还不支持Java 8吗?

12:13:44.226 [localhost-startStop-1]   ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\dev\workspace_professional_web_development\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\movierental\WEB-INF\classes\com\hemswortht\movierental\annotation\ReleaseYearConstraint.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [C:\dev\workspace_professional_web_development\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\movierental\WEB-INF\classes\com\hemswortht\movierental\annotation\ReleaseYearConstraint.class]; nested exception is java.lang.IllegalArgumentException

和ReleaseYearConstraint.java ......

package com.hemswortht.movierental.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;

import com.hemswortht.movierental.validator.ReleaseYearConstraintValidator;

@Target({ ElementType.TYPE })
@Constraint(validatedBy = ReleaseYearConstraintValidator.class)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ReportAsSingleViolation
public @interface ReleaseYearConstraint {
    String message() default "You have specified invalid search input parameters.";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}

2 个答案:

答案 0 :(得分:1)

这一切都归结为构建中的依赖项版本管理。 我建议你看一下Spring为此提供的各种解决方案:

  • Spring Framework BOM,用于有效管理spring-framework版本
  • Spring IO platform BOM如果你想获得spring-framework,spring组合项目的版本管理(那么spring security),甚至是第三方依赖项

请注意,更改pom中依赖项的顺序并不能完全解决您的问题 - 您最好添加依赖项排除项。

答案 1 :(得分:0)

我明白了!所以基本上你必须使用Spring 4.如果你使用的是Java 8. Spring Security 3.2与Spring 4兼容,所以没关系。

所以我哪里出错?????

您需要确保Spring Security 3.2依赖项在pom中的Spring 4依赖项之后。否则所有弹簧版本都会解决为3.2.6 !!!卫生署。