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

RoboVM: Change View
LibGDX dynamically build (fast) Model
How to perform a combined/parallel scaling and translation animation in JavaFX 8
Constant updating of Conway's Game of Life
Switching between screens Libgdx
Serialization and Deserialization of generic Map for Java and external use
play framework- how to send post request using java code in play framework
Check if eclipse editor document was changed by another editor
Implementing functions in an interpreted programming language
Getting “abc_menu_hardkey_panel_mtrl_mult” duplication error
Java SQLite JDBC - Insert with Autoincrement [duplicate]
Am I returning the correct value from my method & am I writing it correctly?
Getting all elements
Multiple if/else statements not producing the desired output
Eclipse crashes on loading splash screen
Can't find resource for bundle java.util

Categories

HOME
ionic-framework
iterator
iot
react-router
read-eval-print-loop
rsyslog
programming-languages
fsm
retrofit
ojdbc
opengl-es-2.0
autotools
dacpac
fancybox-3
numeral.js
visual-studio-cordova
ef-migrations
http-status-code-504
swingx
csrf-protection
accessor
realex-payments-api
zurb-foundation-6
semantic-analysis
bluestacks
karaf
stringtemplate
language-concepts
wallpaper
cloud-code
force-layout
fusionpbx
android-ble
space-complexity
espeak
sharefile
hilbert-curve
az-application-insights
ruby-on-rails-3.1
dotcover
outlook-2013
strptime
jlink
domain-model
abcpdf9
google-feed-api
passport-google-oauth
grails-tomcat-plugin
intrusion-detection
multi-level
nsfilemanager
rhino-servicebus
goose
srand
separator
reactive-banana
ionic
e10s
umbraco6
offloading
android-imagebutton
device-manager
project-planning
google-reader
mesa
valueconverter
valuechangelistener
soundtouch
cos
gwt-rpc
yui-compressor
android-screen-support
mhtml
twrequest
onsubmit
getmessage
chrono
hgsubversion
gnustep
stage
xtype
self-extracting
telerik-scheduler
wise
simpletest
noscript

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App