ClassFormatError when using @Secured and @RequestMapping for the same method

I got a weird error when I try to use @Secured

or @PreAuthorize

in a method @Controller

already annotated with @RequestMapping

. This results in an error when trying to start the application (using spring STS 2.8.1 with vFabric 2.6.1 on win 7 32 bits, both with spring and spring security 3.1):

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file com/dnp/web/controllers/HomeController
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(
    at java.lang.ClassLoader.defineClass(
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(
    at org.apache.catalina.loader.WebappClassLoader.findClass(
    at org.apache.catalina.loader.WebappClassLoader.loadClass(
    at org.apache.catalina.loader.WebappClassLoader.loadClass(
    at org.springframework.util.ClassUtils.forName(
    ... 43 more


And the controller code:

public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {"Welcome home! the client locale is "+ locale.toString());

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

        String formattedDate = dateFormat.format(date);

        model.addAttribute("serverTime", formattedDate );

        return "home";


I don’t know why this error occurs and didn’t find anything on the internet. In addition, protected annotations at the service level work seamlessly.

PD: The full application trace is here: and the main security context and servlet sections are:


source to share

3 answers

It looks like the problem is caused by some strange conflict between Spring AOP and AspectJ compilation in time with the same methods: I use aspect to advise controller method calls and it has been compiled in controllers. So the solution was to just turn off AspectJ compilation and now it works without issue.



@rabusmar I got this link from SpringForum

It looks like PreAuthorize and query mapping are incompatible. They gave the solution at the end of the page. Just try it.

Also, a ClassFormatError is thrown when a class already processed by one annotation is processed again by another annotation, in your case the HomeController may have already been processed by PreAuthorize and again using RequestMapping or vice versa, and this is the reason you get a ClassFormatError.

You can try to find a solution in this spring forum link I pointed out above.



I came across a similar ClassFormatError in some groovy code. But the error message does not indicate which method name & signature was duplicated.

I found the error by running the following command:

javap -private -c io.cloudsoft.mapr.m3.MasterNodeImpl | grep -A 1 '^$' | sort | uniq -c | less


It finds all the method signatures here (always preceded by a blank line in my javap output) and then counts the unique occurrences so I can see which method signature is duplicated. I hope others do a great job with this.

(For those wondering, my problem was groovy's weird behavior @InheritConstructors who somehow added a no-arg constructor twice).



All Articles