此内容没有您所选择的语言版本。

28.10. Deploying custom resources


On start up, Seam scans all JARs containing /seam.properties, /META-INF/components.xml or /META-INF/seam.properties for resources. For example, all classes annotated with @Name are registered on start as Seam components.
You can also use Seam to handle custom resources — that is, Seam can handle specific annotations. First, provide a list of annotation types to handle in the /META-INF/seam-deployment.properties files, like so:
# A colon-separated list of annotation types to handle 
org.jboss.seam.deployment.annotationTypes=com.acme.Foo:com.acme.Bar
Copy to Clipboard Toggle word wrap
Then, collect all classes annotated with @Foo on application start up:
@Name("fooStartup")
@Scope(APPLICATION)
@Startup
public class FooStartup {

   @In("#{deploymentStrategy.annotatedClasses['com.acme.Foo']}")
   private Set<Class<Object>> fooClasses;
   
   @In("#{hotDeploymentStrategy.annotatedClasses['com.acme.Foo']}")
   private Set<Class<Object>> hotFooClasses;

   @Create
   public void create() {
      for (Class clazz: fooClasses) {
         handleClass(clazz);
      }
      for (Class clazz: hotFooClasses) {
         handleClass(clazz);
      }
   }
   
   public void handleClass(Class clazz) {
       // ...
   }

}
Copy to Clipboard Toggle word wrap
You can also set Seam to handle any resource. For example, if you want to process files with the .foo.xml extension, you can write a custom deployment handler:
public class FooDeploymentHandler implements DeploymentHandler { 
  private static DeploymentMetadata FOO_METADATA = new DeploymentMetadata() {

    public String getFileNameSuffix() {
      return ".foo.xml";
    }
  };
  
  public String getName() { 
    return "fooDeploymentHandler"; 
  } 

  public DeploymentMetadata getMetadata() {
    return FOO_METADATA;
  }
}
Copy to Clipboard Toggle word wrap
This provides us with a list of all files with the .foo.xml suffix.
Next, register the deployment handler with Seam in /META-INF/seam-deployment.properties:
# For standard deployment 
# org.jboss.seam.deployment.deploymentHandlers=
#    com.acme.FooDeploymentHandler
 
# For hot deployment 
# org.jboss.seam.deployment.hotDeploymentHandlers=
#    com.acme.FooDeploymentHandler
Copy to Clipboard Toggle word wrap
You can register multiple deployment handlers with a comma-separated list.
Seam uses deployment handlers internally to install components and namespaces, so the handle() is called too early in Seam bootstrap to be useful. You can access the deployment handler easily during the start up of an application-scoped component:
@Name("fooStartup") 
@Scope(APPLICATION) 
@Startup 
public class FooStartup { 
  @In("#{deploymentStrategy.deploymentHandlers['fooDeploymentHandler']}")
  private FooDeploymentHandler myDeploymentHandler;
  @In("#{hotDeploymentStrategy.deploymentHandlers['fooDeploymentHandler']}")
  private FooDeploymentHandler myHotDeploymentHandler;
  @Create public void create() { 
    for (FileDescriptor fd: myDeploymentHandler.getResources()) {
      handleFooXml(fd);
    } 
    for (FileDescriptor f: myHotDeploymentHandler.getResources()) {
      handleFooXml(fd);
    } 
  }
  
  public void handleFooXml(FileDescriptor fd) {
      // ...
  } 
}
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat