java - Spring MVC multiple controllers of the same class -


i want have 1 controller class, 4 instances of it, each of instance have own datasource , controller path, else (methods, validations rules, views names) same;

so need :

class mycontroller{        private myservice service;        @requestmapping("somework")       public string handlerequest(){           ........       }           .................... } 

configuration class :

@configuration @enablewebmvc public class appconfiguration {        @controller              // assuming exists        @requestmapping('con1')  // desired result       mycontroller controller1(){           mycontroller con = new mycontroller();           con.setservice(service1bean);           return con;       }        @controller              // assuming exists        @requestmapping('con2')  // desired result       mycontroller controller2(){           mycontroller con = new mycontroller();           con.setservice(service2bean);           return con;       }         ...............................   } 

no, can't this.

first, annotations set in stone @ compile time. constant meta data cannot modify. though, accessible @ run time through reflection, cannot modify them.

second, @controller annotation call used annotate types. cannot use on method. there no corresponding annotation in spring mvc want in example. (you write own.)

finally, spring mvc stack registers @controller beans' methods handlers mapping them various url patterns provide. if tries register pattern has been registered, fails because duplicate mappings not allowed.

consider refactoring. create @controller class each path want move logic @service bean can customize use whatever data source need.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -