java


Registering spring mvc controllers dynamically


I'm currently working on a web application where the client (AngularJS) calls RESTful APIs (implemented using spring MVC). My controllers currently look something like this:
#RestController
#RequestMapping("myapp/employees")
public class EmployeesController{
#Autowired
private Bus bus;
#RequestMapping("/", POST)
public void hireEmployee(#RequestBody HireEmployeeCommand hireEmployeeCommand){
bus.send(hireEmployeeCommand);
}
#RequestMapping("/", DELETE)
public void fireEmployee(#RequestBody FireEmployeeCommand fireEmployeeCommand){
bus.send(fireEmployeeCommand);
}
//etc...
}
Where Commands are DTOs that model a request to a particular transaction (they serve the same purpose of a command in CQRS or a request model in a uncle Bob's Clean Architecture).
The fact that spring is taking care of dispatching the requests to controllers and mapping them to parameters is very convenient. However, I was wondering if there's a way I can make this leaner probably by writing a DSL that will make controller registration look something like this:
routesFor("myapp/employees")
.post("/", HireEmployeeCommand.class)
.delete("/", FireEmployeeCommand.class);
and somewhere else I will have a unified request handler that looks something like:
public void handleRequest(CommandBase cmd){
//CommandBase is the base class of all commands
//cmd should be a concrete implementation of CommandBase
//properties of cmd should have been mapped from the HttpRequest using whatever object mapping utility spring uses
bus.send(cmd);
}
Is there anyway I can configure spring to "map" the requests to their corresponding commands and dispatch them to the generic request handler?

Related Links

Android application crashing when inserting row to SQlite?
Spring controller called twice while playing video with vlc-plugin
Duplicate Property mapping exception in hibernate
ListIterator.next() returns null
How can I set my back end values to my form text field in play framework
Convert List<Object[]> to JSON
unsuccessful build of a java program with netbeans
Why are changes in a dependency not propagated to the project, which uses it?
Spring 4 - addResourceHandlers not resolving the static resources
How do I fix this: Ant cannot “find file” when trying to build a Java web application on Jenkins?
How can I make Simple not to serialize empty ArrayList?
Java unit testing - how to unit test an async method (uses callback) with mockito answer
Escaping Special Character Java JSON [closed]
How do I use a Hibernate entity-interceptor with JPA transaction manager?
Decode unicode character representation from scraped JavaScript text using Java/Scala
libgdx Music instance obtained from passed reference to object not playing on android but playing on desktop

Categories

HOME
cakephp
hive
coq
zeromq
activiti
azure-data-factory
homebrew
relative-path
view
relay
bpmn
at-command
rdf
c#-2.0
django-imagekit
maude-system
usergrid
ups
vaadin7
progressive-web-apps
finite-automata
sms-gateway
text-rendering
code-review
beyondcompare
emulator
predix
autoconf
arabic
extjs5
claims-based-identity
trading
emgucv
sparse-matrix
facebook-access-token
chromebook
tooltipster
wtx
atlassian-crucible
flink-streaming
pdb
caret
normal-distribution
picasso
io-redirection
x11-forwarding
libraries
starteam
jna
temporary-files
ncalc
gulp-sourcemaps
g-code
glew
netcdf4
thin
jsch
scrollable
prolog-setof
git-diff
slickedit
nsarray
windows-mobile-6.5
r-forge
mako
objective-c-swift-bridge
yt-project
google-feed-api
asp.net-4.5
xml-attribute
ubuntu-10.04
hover-over
whois
fadeout
cloudbees
energy
javax.sound.midi
iad
t4mvc
tarjans-algorithm
sankey-diagram
cisco-ios
streambase
umbraco6
formatjs
website-monitoring
modalpopup
dml
navigationservice
datagridviewcolumn
quantlib-swig
mqx
wsdl-2.0
angularjs-controller
tomcat-valve
servicehost
sproutcore-2
gamma
icanhaz.js
perfect-hash
firefox-5
webkit.net
zune
grid-system
dbisam

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App