tags:

views:

79

answers:

4

do all java mvc based frameworks require you to wire up each and every file in a config file?

like in .net you can create generic routes that map to things like:

controller/action/parameter

I'm currently reading up on spring, but haven't reach the MVC part yet.

A: 

Most are transitioning to default mappings (based on naming conventions) and annotations.

can you please provide an example?
Nir Levy
This is one example from the Struts 2 documentations (there are others): http://www.vaannila.com/struts-2/struts-2-example/struts-2-annotation-example-1.html (Follow up: http://www.vaannila.com/struts-2/struts-2-example/struts-2-annotations-example-1.html)
The Convention Plugin is actually directly inspired by the great principles implemented in Stripes.
Pascal Thivent
not to mention Ruby on Rails ...
+1  A: 

Most of them, but not all. More precisely, have a look at Stripes, a presentation framework that uses "convention over configuration" and allows near to zero configurations (no XML, no annotations).

Pascal Thivent
A: 

JSF 2, Sun's own MVC framework, doesn't require that thanks to the new annotations.

JSF is covered in Java EE 6 tutorial part II chapters 4-9. At IBM developerworks there's also a nice summary about getting rid of XML configurations with help of JSF 2 annotations.

BalusC
+3  A: 

Spring MVC allows this thing then org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping is active, for example, given config:

<beans ...>

<context:component-scan base-package="some.controllers" />

<bean class = "org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

</beans>

And controller implementation:

package some.controllers;

...

@Controller
public class SampleController {

    @RequestMapping
    public String hello() {
        ...
    }

    @RequestMapping
    public String bye() {
        ...
    }
}

URLs /sample/hello and /sample/bye will be mapped to the corresponding methods. For controller/action/parameter kind of mapping controller looks so:

@RequestMapping("/hello/{parameter}")
public String hello(@PathVariable("parameter") String parameter) {
    ...
}
axtavt
ok that is more like it, very straight forward and way less xml to manage!
mrblah