이 콘텐츠는 선택한 언어로 제공되지 않습니다.

5.5. Conditional installation


The @Install annotation controls conditional installation of components that are required in some deployment scenarios and not in others. This is useful when you want to:
  • mock out an infrastructural component in a test,
  • change a component's implementation in certain deployment scenarios, or
  • install some components only if their dependencies are available. (This is useful for framework authors.)
@Install lets you specify precedence and dependencies.
The precedence of a component is a number that Seam uses to decide which component to install when there are multiple classes with the same component name in the classpath. Seam will choose the component with the higher precendence. Some predefined precedence values are (in ascending order):
  1. BUILT_IN — the lowest precedence components are the components built in to Seam.
  2. FRAMEWORK — components defined by third-party frameworks may override built-in components, but are overridden by application components.
  3. APPLICATION — the default precedence. This is appropriate for most application components.
  4. DEPLOYMENT — for application components which are deployment-specific.
  5. MOCK — for mock objects used in testing.
Suppose we have a component named messageSender that talks to a JMS queue.
@Name("messageSender") 
public class MessageSender { 

  public void sendMessage() { 
    //do something with JMS 
  } 
}
Copy to Clipboard Toggle word wrap
In our unit tests, there is no available JMS queue, so we would like to stub out this method. We'll create a mock component that exists in the classpath when unit tests are running, but is never deployed with the application:
@Name("messageSender") 
@Install(precedence=MOCK) 
public class MockMessageSender extends MessageSender { 
  public void sendMessage() { 
    //do nothing! 
  } 
}
Copy to Clipboard Toggle word wrap
The precedence helps Seam decide which version to use when it finds both components in the classpath.
If we are able to control precisely which classes are in the classpath, this works well. But if we are writing a reuseable framework with many dependencies, we do not want to have to break that framework across multiple jars. We want to be able to decide which components to install based on other installed components, and classes available in the classpath. The @Install annotation also controls this functionality. Seam uses this mechanism internally to enable the conditional installation of many built-in components.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat