SeamFramework.orgCommunity Documentation
Além da adição de META-INF/beans.xml
ou WEB-INF/beans.xml
, nenhuma outra configuração especial na sua aplicação é necessária.
Se você estiver usando o JBoss AS 5.0.1.GA, então precisará instalar a Web Beans como um extra. Primeiro, precisamos dizer à Web Beans onde o JBoss está localizado. Editar o jboss-as/build.properties
e definir a propriedade jboss.home
. Por exemplo:
jboss.home=/Applications/jboss-5.0.1.GA
Agora podemos instalar a Web Beans:
$ cd webbeans-$VERSION/jboss-as $ ant update
Um novo deployer webbeans.deployer
é adicionado ao JBoss AS. Isso adiciona suporte a implantações JSR-299 no JBoss AS e permite à Web Beans consultar o EJB3 container e descobrir quais EJBs estão instalados na sua aplicação.
A Web Beans está embutida em todas as versões do JBoss AS a partir da versão 5.1.
Web Beans can be used in any Servlet container such as Tomcat 6.0 or Jetty 6.1.
Web Beans doesn't support deploying session beans, injection using @EJB
, or @PersistenceContext
or using transactional events in Servlet containers.
Web Beans should be used as a web application library in a servlet container. You should place webbeans-servlet.jar
in WEB-INF/lib
. webbeans-serv;et.jar
is an "uber-jar" provided for your convenience. Instead, you could use its component jars:
jsr299-api.jar
webbeans-api.jar
webbeans-spi.jar
webbeans-core.jar
webbeans-logging.jar
webbeans-servlet-int.jar
javassist.jar
dom4j.jar
You also need to explicitly specify the servlet listener (used to boot Web Beans, and control its interaction with requests) in web.xml
:
<listener> <listener-class>org.jboss.webbeans.environment.servlet.Listener</listener-class> </listener>
O Tomcat tem um JNDI apenas de leitura. Assim, a Web Beans não pode vincular automaticamente o Manager. Para vincular o Manager no JNDI, você deve adicionar o seguinte ao seu META-INF/context.xml
:
<Resource name="app/Manager" auth="Container" type="javax.inject.manager.Manager" factory="org.jboss.webbeans.resources.ManagerObjectFactory"/>
e torná-lo disponível para a sua implantação, acrescentando-o ao web.xml
:
<resource-env-ref> <resource-env-ref-name> app/Manager </resource-env-ref-name> <resource-env-ref-type> javax.inject.manager.Manager </resource-env-ref-type> </resource-env-ref >
Tomcat only allows you to bind entries to java:comp/env
, so the Manager will be available at java:comp/env/app/Manager
Web Beans also supports Servlet injection in Tomcat. To enable this, place the webbeans-tomcat-support.jar
in $TOMCAT_HOME/lib
, and add the following to your META-INF/context.xml
:
<Listener className="org.jboss.webbeans.environment.tomcat.WebBeansLifecycleListener" />
Apart from improved integration of the Enterprise Java stack, Web Beans also provides a state of the art typesafe, stateful dependency injection framework. This is useful in a wide range of application types, enterprise or otherwise. To facilitate this, Web Beans provides a simple means for executing in the Java Standard Edition environment independently of any Enterprise Edition features.
When executing in the SE environment the following features of Web Beans are available:
Simple Web Beans (POJOs)
Typesafe Dependency Injection
Application and Dependent Contexts
Binding Types
Stereotypes
Typesafe Event Model
To make life easy for developers Web Beans provides a special module with a main method which will boot the Web Beans manager, automatically registering all simple Web Beans found on the classpath. This eliminates the need for application developers to write any bootstrapping code. The entry point for a Web Beans SE applications is a simple Web Bean which observes the standard @Deployed Manager
event. The command line paramters can be injected using either of the following:
@Parameters List<String> params;
@Parameters String[] paramsArray; // useful for compatability with existing classes
Here's an example of a simple Web Beans SE application:
@ApplicationScoped
public class HelloWorld
{
@Parameters List<String> parameters;
public void printHello( @Observes @Deployed Manager manager )
{
System.out.println( "Hello " + parameters.get(0) );
}
}
Web Beans SE applications are started by running the following main method.
java org.jboss.webbeans.environments.se.StartMain <args>
If you need to do any custom initialization of the Web Beans manager, for example registering custom contexts or initializing resources for your beans you can do so in response to the @Initialized Manager
event. The following example registers a custom context:
public class PerformSetup
{
public void setup( @Observes @Initialized Manager manager )
{
manager.addContext( ThreadContext.INSTANCE );
}
}
The command line parameters do not become available for injection until the @Deployed Manager
event is fired. If you need access to the parameters during initialization you can do so via the public static String getParameters()
method in StartMain
.