Spring 3.1 Web应用程序问题

问题描述:

我正在用一个控制器开发简单的spring mvc应用程序.部署war文件时,出现以下异常.

I was developing simple spring mvc app with one controller. when i deploy the war file, I am getting following exception.

java.lang.IllegalAccessError: tried to access class org.springframework.core.convert.support.StringToBooleanConverter from class org.springframework.core.convert.support.DefaultConversionService
    at org.springframework.core.convert.support.DefaultConversionService.addScalarConverters(DefaultConversionService.java:61)
    at org.springframework.core.convert.support.DefaultConversionService.addDefaultConverters(DefaultConversionService.java:53)
    at org.springframework.core.convert.support.DefaultConversionService.<init>(DefaultConversionService.java:42)
    at org.springframework.core.env.AbstractPropertyResolver.<init>(AbstractPropertyResolver.java:44)
    at org.springframework.core.env.PropertySourcesPropertyResolver.<init>(PropertySourcesPropertyResolver.java:42)
    at org.springframework.core.env.AbstractEnvironment.<init>(AbstractEnvironment.java:95)
    at org.springframework.core.env.StandardEnvironment.<init>(StandardEnvironment.java:54)
    at org.springframework.web.context.support.StandardServletEnvironment.<init>(StandardServletEnvironment.java:43)
    at org.springframework.web.servlet.HttpServletBean.<init>(HttpServletBean.java:90)
    at org.springframework.web.servlet.FrameworkServlet.<init>(FrameworkServlet.java:211)
    at org.springframework.web.servlet.DispatcherServlet.<init>(DispatcherServlet.java:303)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

这听起来像是类加载器问题.在遇到因MyEclipse加载不同的jar文件而不是我认为由应用程序加载的jar文件而引起的冲突之前,我曾遇到过这种情况!

It sounds like a classloader issue. I've run into this before when I ran into conflicts arising from MyEclipse loading different jar files instead of the ones I thought were loaded by the application!

一种检查方法是运行 Process Explorer 并查看加载到内存中的jar文件及其起源.

One way to check is to run Process Explorer and look at the jar files that are loaded into memory and where they originated.

为了更详细地说明您遇到的错误,我引用了

To get more specific with the error you are getting, I'm quoting from the JVM 7 specification that lists that exact error in 5.4.3.1.:

5.3.创建和加载

在运行时,一个类或接口不是仅由其名称决定的,而是由一个对决定的:其二进制名称(第4.2.1节)及其定义的类加载器.接口属于单个运行时程序包. 类或接口的运行时程序包由程序包名称和定义该类或接口的类加载器确定.

At run time, a class or interface is determined not by its name alone, but by a pair: its binary name (§4.2.1) and its defining class loader. Each such class or interface belongs to a single run-time package. The run-time package of a class or interface is determined by the package name and defining class loader of the class or interface.

5.4.3.1.类和接口分辨率

要从D解析由N表示的类或接口C的未解析符号引用,请执行以下步骤:

To resolve an unresolved symbolic reference from D to a class or interface C denoted by N, the following steps are performed:

D的定义类加载器用于创建用N表示的类或接口.该类或接口是C.该过程的详细信息在§5.3中给出.

The defining class loader of D is used to create a class or interface denoted by N. This class or interface is C. The details of the process are given in §5.3.

由于类或接口创建失败而引发的任何异常都可以因类和接口解析失败而引发.

Any exception that can be thrown as a result of failure of class or interface creation can thus be thrown as a result of failure of class and interface resolution.

如果C是数组类,并且其元素类型是引用类型,则通过递归调用第5.4.3.1节中的算法来解析对表示元素类型的类或接口的符号引用.

If C is an array class and its element type is a reference type, then the symbolic reference to the class or interface representing the element type is resolved by invoking the algorithm in §5.4.3.1 recursively.

最后,检查对C的访问权限: 如果D无法访问C(第5.4.4节),则类或接口解析将引发IllegalAccessError.

Finally, access permissions to C are checked: If C is not accessible (§5.4.4) to D, class or interface resolution throws an IllegalAccessError.

例如,如果C是最初声明为公共但在D编译后更改为非公共的类,则会发生这种情况.

This condition can occur, for example, if C is a class that was originally declared to be public but was changed to be non-public after D was compiled.

如果第1步和第2步成功但第3步失败,则C仍然有效且可用.但是,解析失败,并且D被禁止访问C.

If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution fails, and D is prohibited from accessing C.

总而言之,听起来罐子来自另一个包,也就是另一个类加载器.

To sum it all up, it sounds like the jar is from a different package, that is from another classloader.