Spring

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
Line 58: Line 58:
 
== Spring and Quercus ==
 
== Spring and Quercus ==
  
Quercus PHP scripts can retrieve Spring beans using the spring_bean() method:
+
Quercus PHP scripts can retrieve Spring beans using the spring_bean() method.
  
 +
# Create a test.php in webapps/spring/test.php as follows:
 +
 +
  <?php
 +
 
   $bean = spring_bean("foo");
 
   $bean = spring_bean("foo");
 +
 +
  var_dump($bean);
 +
  ?>

Revision as of 16:03, 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.

  1. download Resin from http://caucho.com/download
  2. unzip resin into /usr/local/share/resin
  3. create /usr/local/share/resin/webapps/spring/WEB-INF/lib
  4. copy the Spring jars into WEB-INF
  5. start Resin with "java -jar /usr/local/share/resin/lib/resin.jar"

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 WEB-INF/resin-web.xml, you can configure Spring's 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.

  1. Create a test.php in webapps/spring/test.php as follows:
 <?php

 $bean = spring_bean("foo");

 var_dump($bean);
 ?>
Personal tools