问题
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)
回答1:
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!
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. Creation and Loading
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. Class and Interface Resolution
To resolve an unresolved symbolic reference from D to a class or interface C denoted by N, the following steps are performed:
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.
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.
Finally, access permissions to C are checked: If C is not accessible (§5.4.4) to D, class or interface resolution throws an IllegalAccessError.
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.
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.
来源:https://stackoverflow.com/questions/9366842/spring-3-1-web-application-issue