|
Tutorial
This tutorial explains how to create a simple Spring+Flower-powered web app
Note: Not all the listed libs are probably needed, but this is how they are downloaded from the Maven repository (and if you look in the Ivy config file, you'll notice that there are already tons of useless libs excluded -- if you need them, delete the exclude tag)
<servlet>
<servlet-name>flowerServlet</servlet-name>
<servlet-class>net.danielkvasnicka.flower.FlowerDispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>flowerServlet</servlet-name>
<url-pattern>/the/url/pattern/you/want/flower/to/be/sensitive/to</url-pattern>
</servlet-mapping>
<!-- FLOWER config --> <import resource="classpath:net/danielkvasnicka/flower/core/flowerContext.xml"/> <bean id="webAccessibleBeanResolver" class="net.danielkvasnicka.flower.core.DefaultWebAccessibleBeanResolver" autowire-candidate="true" /> <!-- FLOWER config -->
<bean id="firstBean" class="net.danielkvasnicka.flower.test.beans.TestWebAccessibleBean" f:url-mapping="/helloworld/({f_method}[a-zA-Z]+)/({x}\d*)" />Don't forget registering the namespace for "f". Add xmlns:f="http://www.danielkvasnicka.net/ns/flower/spring" to the root tag and http://www.danielkvasnicka.net/ns/flower/spring http://ns.danielkvasnicka.net/flower/spring-flower.xsd to its xsi:schemaLocation attribute. This is taken from the test context available in the Flower sources and it says: when the client requests an URL that conforms to /helloworld/({f_method}[a-zA-Z]+)/({x}\d*) then take this bean and call method, whose name is stored in the named group "f_method" (all named groups staring with f_ are reserved to Flower internals). So when you call /helloworld/index/3, the bean is retrieved from the context, its parameters property is populated with a map containing {x=3} and the method index() is called. The returned Response instance is then sent (by calling send()) to the client. For more info on how to create the beans, consult the test sources: http://code.google.com/p/spring-flower/source/browse/trunk/#trunk/test/net/danielkvasnicka/flower/test/beans |