0

It's strange that my PUT operations is not mapped to spring method, I've following classes...

@Controller
@RequestMapping(value = { "/**/applicationContext/abcde" })
public abstract class AbstractController { 
  // Exception handlers
}

This class is extended by another abstract class, as below

public abstract class AbstractAdapter extends AbstractController{}

Finally, above class is extended by below class

public class SpringAdapter extends AbstractAdapter implements MyInterface{}

And I've some put operations to be made which looks like below :-

@Override
@ResponseBody
@RequestMapping(method = { RequestMethod.PUT }, consumes = "application/x-www-form-urlencoded",     produces = "application/xml", params = {
        "param1=some_value", param2 })
public MyObject update(
        @RequestParam(value = param2, required = true) @ContentType(value = Encoding.XML)     MyObejct myObject, HttpServletRequest request) throws Exception{ }

But when I invoke put method then the request is not mapping to my update method. Can anybody please help.

Akhil
  • 1,184
  • 1
  • 18
  • 42
  • Do you really sure that your request contains all required options? `Content-Type` and `Accept` headers. The URL has `param1=some_value` and I guess that `param2` is a static const with in the similar `myParam=myValue` style. – Artem Bilan Jan 13 '15 at 12:51
  • 1
    I would also be curious to hear if your SpringAdapter actually uses the @Controller annotation. Otherwise it will not be scanned and therefor not be found – Joeblade Jan 13 '15 at 12:51
  • @Joeblade: Since my parent class has been marked with Controller annotation and hence I do not need to mark my SpringAdapter with Controller annotation. – Akhil Jan 13 '15 at 12:56
  • @ArtemBilan : The param1 is constant but the param2 is a XML. – Akhil Jan 13 '15 at 12:57
  • 1
    @akhil I added an answer, as I think the Controller isn't inherited. I recommend you test your assumption (inheritance works with controller annotation) with a simple example that works when parent and child have controller, and then works/doesn't work when child class doesn't have controller – Joeblade Jan 13 '15 at 13:13

1 Answers1

2

Your subclass isn't marked as a @Controller and therefor Spring (when it scans for controllers) doesn't find it.

Please see this answer

Basically, annotations aren't inherited by default. You can use an annotation in the declaration of an annotation to mark it as inherited as is shown here by using:

public @interface Inherited

but if you look at the controller source, this keyword is not used in the Controller implementation spring uses.

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {

So I would assume @Controller is not inherited in your situation. I would first try out the inheritance with a simple example (class A extends class B , with just a simple unadorned method) to verify this.

Community
  • 1
  • 1
Joeblade
  • 1,735
  • 14
  • 22
  • Thanks for your suggestion, the problem was My child class was not marked with Controller annotations, marking it with controller got me through this issue. – Akhil Jan 14 '15 at 06:10