Spring
From Resin 3.0
(Difference between revisions)
(New page: == Spring and Resin WebBeans == Spring can be configured to use Resin's WebBeans as a parent BeanFactory. This gives Spring access to any bean configured in Resin, including databases, E...) |
|||
Line 10: | Line 10: | ||
<web-app xmlns="http://caucho.com/ns/resin"> | <web-app xmlns="http://caucho.com/ns/resin"> | ||
+ | |||
+ | <database name="jdbc/mysql"> | ||
+ | .... | ||
+ | </database> | ||
<context-param parentContextKey="resin-webbeans-factory"/> | <context-param parentContextKey="resin-webbeans-factory"/> | ||
Line 29: | Line 33: | ||
</beans> | </beans> | ||
+ | For a FooBean: | ||
+ | package qa; | ||
+ | |||
+ | import javax.sql.DataSource; | ||
+ | |||
+ | public class FooBean { | ||
+ | private DataSource _database; | ||
+ | |||
+ | public void setDatabase(DataSource database) | ||
+ | { | ||
+ | _database = database; | ||
+ | } | ||
+ | |||
+ | ... | ||
+ | } | ||
== Spring and Quercus == | == Spring and Quercus == |
Revision as of 03:16, 14 January 2008
Spring and Resin WebBeans
Spring can be configured to use Resin's WebBeans as a parent BeanFactory. This gives Spring access to any bean configured in Resin, including databases, EJBs, JMS items, and Resin <bean> items.
The resin-support.jar must be in the WEB-INF/lib (or ext-webapps)
The class of the ApplicationContext is com.caucho.spring.ResinApplicationContext.
In the resin-web.xml, you can configure Springs listener to use Resin as the parent ApplicationContext as follows:
<web-app xmlns="http://caucho.com/ns/resin"> <database name="jdbc/mysql"> .... </database> <context-param parentContextKey="resin-webbeans-factory"/> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
Spring beans defined in the applicationContext.xml can use Resin beans as <ref> values:
<beans> <bean class="qa.FooBean" name="foo"> <property name="database" ref="jdbc/mysql"/> </bean> </beans>
For a FooBean:
package qa; import javax.sql.DataSource; public class FooBean { private DataSource _database; public void setDatabase(DataSource database) { _database = database; } ... }
Spring and Quercus
Quercus PHP scripts can retrieve Spring beans using the spring_bean() method:
$bean = spring_bean("foo");