Trying to upgrade from Restlet 2.2 to 2.3 and I got a warning for Component main. In the javadocs it says: "Use XML support in the Spring extension instead." but I'm not able to find any examples of this. Anyone have an example to get me started? I am using the jse version from the command line to run my server.
Yes, the XML configuration for Restlet component is now deprecated and you should use the Spring XML one. For this, you need to add the extension Spring (org.restlet.ext.spring) within your application. If you use Maven, simply add this:
<dependencies>
(...)
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.spring</artifactId>
<version>${restlet-version}</version>
</dependency>
</dependencies>
Here is a sample of the configuration of the Restlet component within a Spring XML configuration:
<beans>
<bean id="top" class="org.restlet.ext.spring.SpringComponent">
<property name="server">
<bean class="org.restlet.ext.spring.SpringServer">
<constructor-arg value="http" />
<constructor-arg value="3000" />
</bean>
</property>
<property name="defaultTarget" ref="default" />
</bean>
<bean id="default" class="org.restlet.ext.spring.SpringRouter">
<property name="attachments">
<map>
<entry key="/myapp" value-ref="applicationRouter" />
</map>
</property>
</bean>
</beans>
You can define the router for your application as described below:
<beans>
<bean id="applicationRouter"
class="org.restlet.ext.spring.SpringRouter">
<property name="attachments">
<map>
<entry key="/users/{username}">
<bean class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="create"
bean="userResource" />
</bean>
</entry>
(...)
</map>
</property>
</bean>
</beans>
You can simply then start your Restlet application, as described below, by creating a Spring container and getting the component from it:
// Load the Spring application context within classpath
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "applicationContext-router.xml",
"applicationContext-server.xml" });
// Obtain the Restlet component from the context and start it
Component restletComponent = (Component) context.getBean("component");
restletComponent.start();
Hope it helps you, Thierry