![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
injection-based resource configuration (candi)
Resin's configuration uses a powerful, general dependency injection system (CanDI) to configure servlets, Resin resources, databases, application components, third-party libraries and drivers. By understanding a few rules matching the XML to the configured resources, an administrator can have full control over the application server behavior. Because of the importance of verifying and debugging configuration, Resin's configuration is stateless, meaning that the XML files fully describe the configuration of the system. Resin avoids hidden state by avoiding deployment tools and internal, hidden database configuration. Because Resin's configuration (CanDI) creates and updates Java objects, each XML tag exactly matches either a Java class or a Java property. For security and rewrite rules, the JavaDoc helps document the configuration. Your own application's configuration can use its JavaDoc to describe the XML tags, and Resin's configuration files like the META-INF/resin-web.xml to customize your application.
Services, drivers, and third-party libraries are registered and configured using the standard Resin configuration files resin.xml or resin-web.xml files as well as the META-INF/beans.xml. Application services and libraryes are treated as first-class components just like Resin-internal resources, because Resin's own configuration uses the same CanDI configuration. Even standard JavaEE configuration like servlets, JSP .tld files, and EJBs are configured with CanDI. The configuration in Resin is smaller than some other dependency frameworks because only components which need customization need to be in the XML. If your application is using Java Injection internally, most of the wiring occurs automatically through Java code annotations instead of being configured in XML. The annotation focus makes the Java code self-describing, and also simplifies the management by shrinking the needed XML. The XML-configuration lets you customize your application for a
particular environment, e.g. setting configuration parameters. For example,
Resin's In addition, the XML-configuration documents the services you've enabled. For heavyweight services, this documentation is critical, while lightweight components do not need this extra housekeeping overhead. Component overview
The Example: bean and component META-INF/beans.xml
<Beans xmlns="urn:java:ee" xmlns:example="urn:java:example">
<example:MyService>
<ApplicationScoped/>
</example:MyService>
<example:MyComponent>
</example:MyComponent>
</Beans>
The
Some services and components need a name because they're used as a JSP or JSF reference, or because the configuration needs a reference to the component. Resin configuration files can use EL expressions to get references to resources, beans, system properties, and calculate generatal expressions based on those values. Because all Resin's resources are added to the CanDI registry automatically, application components have access to anything they need. Both the JSP immediate syntax and deferred syntax are
supported ( Example: circular references in resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin"
xmlns:qa="urn:java:qa">
<qa:FooBean>
<Named>a</Named>
<qa:bar>#{b}</qa:bar>
</qa:FooBean>
<qa:FooBean>
<Named>b</Named>
<qa:bar>#{a}</qa:bar>
</qa:FooBean>
</web-app>
You can also use beans as factories in the EL expressions, because
Resin's EL implementation allows method expressions. If the bean's
create method is named Resin's Java Injection configuration uses the standard JavaBeans patterns to configure properties. Resin uses the same mechanism for all of its own configuration parsing, including every JavaEE configuration file, the resin-web.xml and the resin.xml itself. So your application will have all the configuration flexibility it needs. Since the component beans can use Java
Injections, injected components are typically not configured in
the resin-web.conf, avoiding the need for tags like Example: Hello.java
package example;
public class Hello {
public void setGreeting(String greeting);
}
The basic example sets a Example: META-INF/beans.xml configuring a singleton
<Beans xmlns="urn:java:ee" xmlns:example="urn:java:example">
<example:Hello>
<example:greeting>Hello, World</example:greeting>
</example:Hello>
</Beans>
primitive conversionsResin automatically converts XML values to the Java property types
for most primitive values. For other primitive types, it also supports
the JavaBeans
compound typesFull sub-bean configuration is also available when a service needs a more complicated configuration than primitives allow. The service class can add sub-beans as properties and the sub-beans themselves are configured recursively using Resin's configuration. Since all JavaEE configuration files like the web.xml and the *.tld files are configured using Resin's recursive sub-bean configuration, your application has full access to a powerful recursive configuration. A sophisticated application can use Resin's sub-bean configuration to create a full domain-specific language, allowing extensive user control of the application. custom sub-beansExample: sub-bean configuration example
<web-app xmlns="http://caucho.com/ns/resin">
<example:Theater xmlns:example="urn:java:example">
<example:name>Balboa</example:name>
<example:movie title="The Princess Bride"/>
<example:movie title="The Maltese Falcon"/>
</example:Theater>
</web-app>
In this example, the Example: Theater.java
public class Theater {
public void setName(String name);
public void addMovie(Movie movie)
}
Example: Movie.java
public class Movie {
public void setTitle(String title);
}
listSetters taking a List items are specified directly with <value> elements. There is no extra <list> element required. The <list> element is only used when creating a sub-list or sub-element (see below.) Example: MyBean.setValues(List)
<my-bean>
<values>
<value>a</value>
<value>b</value>
<value>c</value>
</values>
</my-bean>
Example: MyBean.setValues(String [])
<my-bean>
<values>
<value>a</value>
<value>b</value>
<value>c</value>
</values>
</my-bean>
In the following example, the argument is an object, so we need
a <list> element to tell Resin to create a list. The object
created will be an Example: MyBean.setValues(Object)
<my-bean>
<values>
<list>
<value>a</value>
<value>b</value>
<value>c</value>
</list>
</values>
</my-bean>
Resin can always use the Example: MyBean.addValue(String) <my-bean> <value>a</value> <value>b</value> <value>c</value> </my-bean> Some beans require constructor configuration because the service or
library designer prefers constructors to method configuration.
Resin's configuration can support these constructor beans with the
Example: MyBean configuration
<web-app xmlns="http://caucho.com/ns/resin"
xmlns:example="urn:java:example">
<example:MyBean>
<new>
<value>first arg<value>
<value>second arg<value>
</new>
</example:MyBean>
</web-app>
Example: MyBean with constructor
public class MyBean {
public MyBean(String a, String b)
{
...
}
}
Single constructorAs a convenience, Resin provides short form of the constructor configuration if there's only a single argument. You can either omit the <value> and just use the <new> tag, or you can even omit the <new> tag entirely. Example: MyBean short form
<web-app xmlns="http://caucho.com/ns/resin"
xmlns:example="urn:java:example">
<example:MyBean>
<new>single arg</new>
</example:MyBean>
</web-app>
Example: MyBean ultra-short form
<web-app xmlns="http://caucho.com/ns/resin"
xmlns:example="urn:java:example">
<example:MyBean>single arg<example:MyBean>
</web-app>
valueOfFor classes which implement a static Example: MyBean with valueOf
public class MyBean {
...
public static MyBean valueOf(String text)
{
MyBean bean = new MyBean();
bean.setTextValue(text);
bean.init();
return bean;
}
}
setValueFor objects with a
Some of your application's beans will be configured as custom services, like Java servlets or Hessian services, using CanDI to configure a service annotation. These custom services combine your own Java code with Resin capabilities, usually to expose them as external web services.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||