I've been using only XML configuration to make MVC web applications (no annotation).
Now I want to make a RESTful web service with Spring but I could not find any tutorial that doesn't use annotation.
Is there a way to build a RESTful web service with only XML configuration ?
Or do I HAVE TO use annotation ?
For example, you can deploy an MVC pattern web application using only XML configuration like below.
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver" id="springParameterMethodNameResolver">
<property name="paramName" value="action"/>
</bean>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<map>
<entry key="/test.do" >
<ref bean="testController" />
</entry>
<entry key="/rest/test">
<ref bean="testRESTController"/>
</entry>
</map>
</property>
</bean>
<!-- My Beans -->
<bean id="testMethodNameResolver" class="com.rhcloud.riennestmauvais.spring.test.TestMethodNameResolver">
</bean>
<!-- Test -->
<bean class="com.rhcloud.riennestmauvais.spring.test.TestController" id="testController">
<property name="delegate" ref="testDelegate"/>
<property name="methodNameResolver" ref="testMethodNameResolver"></property>
<!-- <property name="methodNameResolver" ref="springParameterMethodNameResolver"></property> -->
</bean>
<bean class="com.rhcloud.riennestmauvais.spring.test.TestDelegate" id="testDelegate">
</bean>
However, I hit a wall when I was trying to map a method for URL for example
HTTP method : POST
, URL : /student/1/Adam
- so that I could add a student.
The URL format would be like this: /[resource]/[id]/[name]
I could map /student/1/Adam
to a controller by putting a pattern in the entry key like:
<entry key="/student/regex-to-allow-number/regex-to-allow-string">
But how should I parse the URI within my controller ?
I could parse the URI by using String.split()
or something like that but I'm wondering if there isn't already some solution to this so that I could avoid reinventing the wheel.