サポートエンジニアが語る。weblogic server における cdi 概要・tips 紹介

151
サポートエンジニアが語る。 WebLogic Server における CDI 概要・Tips 紹介 NEC ソリューションイノベータ 第四PFソフトウェア事業部 大谷

Upload: oracle-fusion-middleware

Post on 19-Feb-2017

252 views

Category:

Technology


10 download

TRANSCRIPT

  • WebLogic Server CDI Tips

    NEC

    PF

  • Agenda

    1.

    2. Contexts and Dependency Injection for the Java EE

    platform (CDI)

    3. CDI

    4. WebLogic Server CDI

    5. CDI AP

    6.

    7.

    CDI

    @Qualifier

    @Alternative / @Priority

  • 1.

  • 4 NEC , Ltd. 2016

    NEC Oracle Fusion Middleware

    2005 WebLogic Server WebLogic Integration / WebLogicWorkshop Java / JRockitSOA SuiteBPM / BPEL / ServiceBus Tuxedo SE

  • 2. Contexts and Dependency Injection for the Java EE Platform (CDI)

  • 6 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    New

  • 7 NEC , Ltd. 2016

    HelloImpl-A HelloImpl-B new

    Contexts and Dependency Injection for the Java EE platform (CDI)

    New

    public class Test {private Hello hello;

    public void print() {hello = new HelloImpl-A();hello.sayHello();

    }}

    public class Test {private Hello hello;

    public void print() {hello = new HelloImpl-B();hello.sayHello();

    }}

  • 8 NEC , Ltd. 2016

    new @Inject

    hello

    New

    Contexts and Dependency Injection for the Java EE platform (CDI)

    public class Test {@Injectprivate Hello hello;

    public void print() {hello.sayHello();

    }}

  • 9 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    App

    Variable

    Proxy

    Bean (Impl)Context

    Proxy

    A

    PP

    WorldImpl implements World

    HelloImpl implements Hello

    SampleImpl implements Sample

    New

  • 10 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    CDI

    P145 - @Alternative / @Priority

    CDI Java EE 5 DI /

    JSR-299

    JSR-299: Contexts and Dependency Injection for the Java EE platformhttp://docs.jboss.org/cdi/spec/1.0/html/

    New

    http://docs.jboss.org/cdi/spec/1.0/html/

  • 11 NEC , Ltd. 2016

    CDI

    -

    HTTP

    Contexts and Dependency Injection for the Java EE platform (CDI)

    - Bean

    @RequestScopedpublic class HelloImpl implements Hello, Serializable {

    @Overridepublic String sayHello() {

    return "Hello World";}

    }

    HTTP Bean

    @SessionScopedpublic class HelloImpl implements Hello, Serializable {

    @Overridepublic String sayHello() {

    return "Hello World";}

    }

    Bean

    public class Test {@Injectprivate Hello hello;

    public void print() {hello.sayHello();

    }}

    null

  • 12 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    P9 CDI

    Bean

    new

    Context

    ProxyBean Context

    @Inject Bean (Impl) Proxy

    Bean (Impl)Context

    Proxy

  • 13 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    Bean

    Bean (Instance)Context

    Proxy (Instance)

    12

    9

    6

    3

    CDI Container

    public class Test {@Injectprivate Hello hello;

    public void print() {hello.sayHello();

    }}

    Proxy (Reference)

    A

    PP

    @RequestScopedpublic class HelloImpl implements Hello, Serializable {

    @Overridepublic String sayHello() {

    return "Hello World";}

    }

  • 14 NEC , Ltd. 2016

    CDI GC

    Contexts and Dependency Injection for the Java EE platform (CDI)

    CDI Container

    Context

    12

    9

    6

    3

    Context

    HTTP Session

    12

    9

    6

    3

    Context

    HTTP

    12

    9

    6

    3

    Context

    HTTP

    12

    9

    6

    3

    Context

    HTTP

    12

    9

    6

    3

    Context

    HTTP Session

    12

    9

    6

    3

  • 15 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    Bean

    Interface

    package weblogic.study;

    public interface Hello {public String sayHello();

    }

    Servlet

    package weblogic.study;

    import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.inject.Inject;

    @WebServlet("/cdi.do")public class CDISampleServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @InjectHello hello;

    protected void service(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {System.out.println( hello.sayHello() );

    }}

    Bean

    package weblogic.study;

    import java.io.Serializable;import javax.enterprise.context.RequestScoped;

    @RequestScopedpublic class HelloImpl implements Hello, Serializable {

    private static final long serialVersionUID = 1L;

    @Overridepublic String sayHello() {

    try { Thread.sleep( 10000 ); } catch ( InterruptedException e ) { }return "Hello World";

    }}

    10

    -

  • 16 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    Servlet HelloImpl#sayHello() service()

    weblogic.study.HelloImpl$Proxy$_$$_WeldClientProxy HelloImpl

    "[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'"#22 daemon prio=2 os_prio=-2 tid=0x000000005aa45000 nid=0x2108 waiting on condition [0x000000005bc4e000]java.lang.Thread.State: TIMED_WAITING (sleeping)

    at java.lang.Thread.sleep(Native Method)at weblogic.study.HelloImpl.sayHello(HelloImpl.java:17)at weblogic.study.HelloImpl$Proxy$_$$_WeldClientProxy.sayHello(Unknown Source)at weblogic.study.CDISampleServlet.service(CDISampleServlet.java:26)at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651)at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270)at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)

  • 17 NEC , Ltd. 2016

    CDI Bean

    CDI Bean

    POJO (Plain Old Java Object) Java Beans CDI Bean

    CDI Bean

    Contexts and Dependency Injection for the Java EE platform (CDI)

  • 18 NEC , Ltd. 2016

    Contexts and Dependency Injection for the Java EE platform (CDI)

    CDI

    null

    CDI Java

    CDI CDI

    CDI Bean

    CDI Bean

    CDI Bean

    CDI

  • 3. CDI

    @Inject

    @Named

  • 20 NEC , Ltd. 2016

    CDI

    CDI

    @Inject CDI

    @Named

    CDI Bean CDI Bean JSF EL

  • 21 NEC , Ltd. 2016

    CDI

    Java EE 6 CDI CDI beans.xml XML Web WEB-INF

    0 beans.xml WEB-INF CDI

    Java EE 7 CDI beans.xml beans.xml CDI

    beans.xml

  • 22 NEC , Ltd. 2016

    CDI

    @Inject

    @Inject CDI

    CDI

    import javax.inject.Inject;

    public class Test {@Injectprivate Hello hello;

    public void print() {hello.sayHello();

    }}

    public interface Hello {public void sayHello();

    }

    public class HelloImpl implements Hello {@Overridepublic void sayHello() {

    System.out.println( "Hello World" );}

    }

    @Inject javax.inject.Inject

    @Inject

  • 23 NEC , Ltd. 2016

    CDI

    @Inject

    @Inject

    CDI

    CDI

    @InjectHello hello; WorldImpl implements World

    HelloImpl implements Hello

    SampleImpl implements Sample

    Hello

    Bean (Impl)Context

    Proxy

  • 24 NEC , Ltd. 2016

    CDI

    @Inject

    @InjectHello hello;

    HelloImpl2 implements Hello

    HelloImpl1 implements Hello

  • 25 NEC , Ltd. 2016

    CDI

    @Inject

    @Qualifier

  • 26 NEC , Ltd. 2016

    CDI

    @Named

    CDI Bean

    CDI CDI Bean

    CDI Bean JSF EL CDI Bean

    JSF

    CDI Bean @Named EL

    CDI Bean

    package weblogic.study;

    import java.io.Serializable;import javax.enterprise.context.SessionScoped;import javax.inject.Inject;import javax.inject.Named;

    @SessionScoped@Namedpublic class Test implements Serializable {

    private static final long serialVersionUID = 1L;

    @InjectHello hello;

    public String getHello() {

    return hello.sayHello();}

    }

  • 27 NEC , Ltd. 2016

    CDI

    @Named

    @Named CDI Bean EL Bean

    Named Bean

    @Named

    Bean JSF Bean test

    EL

    @Named( Bean )

    Bean JSF Bean Test

    EL

    @Namedpublic class Test implements Serializable {

  • 28 NEC , Ltd. 2016

    CDI

    @Named

    EL CDI Bean getter

    EL getter

    CDI Bean

    package weblogic.study;

    import java.io.Serializable;import javax.enterprise.context.SessionScoped;import javax.inject.Inject;import javax.inject.Named;

    @SessionScoped@Namedpublic class Test implements Serializable {

    private static final long serialVersionUID = 1L;

    @InjectHello hello;

    public String getHello() {

    return hello.sayHello();}

    }

    JSF

  • 29 NEC , Ltd. 2016

    CDI

    5

    @RequestScoped / @SessionScoped / @ApplicationScoped@ConversationScoped / @Dependent

    @Qualifier

    @Alternative / @Priority

    @Alternative @Priority

  • 30 NEC , Ltd. 2016

    CDI

    @Inject

    CDI

    @Named

    CDI Bean CDI Bean JSF EL

  • 4. WebLogic Server CDI

    JBoss Weld

    Jersey

  • 32 NEC , Ltd. 2016

    WebLogic Server CDI

    JBoss Weld

    WebLogic Server CDI JBoss Weld

    JBoss Weld

    Red Hat Open Source Software

    CDI for Java EE Platform

    WebLogic Server GlassFish JBoss Web

    Weld - CDI Reference Implementation

    http://weld.cdi-spec.org/

    http://weld.cdi-spec.org/

  • 33 NEC , Ltd. 2016

    JBoss Weld

    WebLogic Server JBoss Weld

    JBoss Weld latest stable release 2017/1/17 2.4.1.Final

    WebLogic Server Version Java EE Version JBoss Weld Version

    12.1.1.0.0 Java EE 6 1.1.Final

    12.1.2.0.0 Java EE 6

    1.1.Final

    12.1.3.0.0 Java EE 6

    1.1.Final

    12.2.1.0.0 Java EE 7 2.2.13.Final

    12.2.1.1.0 Java EE 7 2.3.2.Final

    12.2.1.2.0 Java EE 7 2.3.2.Final

    WebLogic Server CDI

  • 34 NEC , Ltd. 2016

    WebLogic Server CDI

    JBoss Weld

    .jar

    12.2.1.0.0

    WebLogic Server Version Library Path

    12.1.1.0.0${MW_HOME}/modules/org.jboss.weld.api_1.0.0.0_1-1-3.SP1.jar${MW_HOME}/modules/org.jboss.weld.core_1.0.0.0_1-1-3.SP1.jar${MW_HOME}/modules/org.jboss.weld.spi_1.0.0.0_1-1-3.SP1.jar

    12.1.2.0.0 ${WL_HOME}/modules/features/weblogic.server.merged.jar

    12.1.3.0.0 ${WL_HOME}/modules/features/weblogic.server.merged.jar

    12.2.1.0.0${WL_HOME}/modules/org.jboss.weld.weld-api.jar${WL_HOME}/modules/org.jboss.weld.weld-core.jar${WL_HOME}/modules/org.jboss.weld.weld-spi.jar

    12.2.1.1.0${WL_HOME}/modules/org.jboss.weld.weld-api.jar${WL_HOME}/modules/org.jboss.weld.weld-core.jar${WL_HOME}/modules/org.jboss.weld.weld-spi.jar

    12.2.1.2.0${WL_HOME}/modules/org.jboss.weld.weld-api.jar${WL_HOME}/modules/org.jboss.weld.weld-core.jar${WL_HOME}/modules/org.jboss.weld.weld-spi.jar

  • 35 NEC , Ltd. 2016

    WebLogic Server CDI

    Jersey

    WebLogic Server JAX-RS Jersey CDI

    Jersey

    Open Source Software

    RESTful Web Service JAX-RS

    Jersey

    https://jersey.java.net/

    https://jersey.java.net/

  • 36 NEC , Ltd. 2016

    Jersey

    WebLogic Server Jersey

    Jersey latest stable release 2017/1/17 2.25

    WebLogic Server 12.1.3.0.0 Jersey

    Oracle WebLogic Server 12.1.3 RESTful Web 12c (12.1.3)

    > [2 Jersey 2.5.1 (JAX-RS 2.0)]

    https://docs.oracle.com/cd/E57014_01/wls/RESTF/use-jersey20-ri.htm

    Oracle WebLogic Server RESTful Web 12c (12.2.1)

    > [Jersey 1.18 (JAX-RS 1.1 RI)RESTful Web]

    http://docs.oracle.com/cd/E72987_01/wls/RESTF/jersey-back-comp.htm

    WebLogic Server Version Java EE Version Jersey Version

    12.1.1.0.0 Java EE 6 1.9

    12.1.2.0.0 Java EE 6 1.17.1

    12.1.3.0.0 Java EE 6 1.18.1

    12.2.1.0.0 Java EE 7 2.21.1

    12.2.1.1.0 Java EE 7 2.22.1

    12.2.1.2.0 Java EE 7 2.22.1

    WebLogic Server CDI

    https://docs.oracle.com/cd/E57014_01/wls/RESTF/use-jersey20-ri.htmhttp://docs.oracle.com/cd/E72987_01/wls/RESTF/jersey-back-comp.htm

  • 37 NEC , Ltd. 2016

    WebLogic Server CDI

    Jersey

    .jar

    WebLogic Server Version Library Path

    12.1.1.0.0${MW_HOME}/modules/com.sun.jersey.core_1.1.0.0_1-9.jar${MW_HOME}/modules/com.sun.jersey.server_1.1.0.0_1-9.jar

    12.1.2.0.0

    ${ORACLE_HOME}/oracle_common/modules/jersey-core-1.17.1.jar${ORACLE_HOME}/oracle_common/modules/jersey-server-1.17.1.jar${ORACLE_HOME}/oracle_common/modules/jersey-servlet-1.17.1.jar

    12.1.3.0.0

    ${ORACLE_HOME}/oracle_common/modules/jersey-core-1.18.jar${ORACLE_HOME}/oracle_common/modules/jersey-server-1.18.jar${ORACLE_HOME}/oracle_common/modules/jersey-servlet-1.18.jar

    12.2.1.0.0

    ${ORACLE_HOME}/oracle_common/modules/org.glassfish.jersey.core.jersey-common.jar${ORACLE_HOME}/oracle_common/modules/org.glassfish.jersey.ext.cdi.jersey-cdi1x.jar${ORACLE_HOME}/oracle_common/modules/org.glassfish.jersey.ext.cdi.jersey-cdi1x-servlet.jar${ORACLE_HOME}/oracle_common/modules/org.glassfish.jersey.ext.cdi.jersey-cdi1x-transaction.jar

    12.2.1.1.0 12.2.1.0.0

    12.2.1.2.0 12.2.1.0.0

  • 38 NEC , Ltd. 2016

    WebLogic Server CDI

    Weld / Jersey CDI

    jBatch (Batch Applications for the Java Platform)

    IBM jBatch CDI

  • 5. CDI AP

    @PostConstruct

    Weld

    Weld .class

  • 40 NEC , Ltd. 2016

    CDI AP

    @PostConstruct

    CDI Bean CDI Bean

    CDI

    CDI

    void ()

    void init() / void initialize()

    @PostConstruct CDI Bean

    @PreDestroy CDI Bean

  • 41 NEC , Ltd. 2016

    CDI AP

    @PostConstruct

    CDI Bean

    @PreDestroy

    CDI Bean

    CDI Bean

    CDI Bean

    @PostConstruct

    @SessionScoped / @ConversationScoped CDI Bean

    @PostConstruct

    @PreDestroy CDI Bean

  • 42 NEC , Ltd. 2016

    CDI AP

    @PostConstruct

    @PostConstruct CDI Bean Logger CDI Bean

    HelloImpl

    package weblogic.study;

    import javax.annotation.PostConstruct;

    public class HelloImpl implements Hello {

    @PostConstructpublic void init() {

    System.out.println( "HelloImpl was injected." );}

    @Overridepublic String sayHello() {

    // TODO Auto-generated method stubreturn "Hello World.";

    }}

    HelloImpl was injected.

  • 43 NEC , Ltd. 2016

    CDI AP

    Weld

    WebLogic Server Weld Weld

    Weld

    How do I enable debug logging for Weld in a specific container?http://weld.cdi-spec.org/documentation/#7

    Weld Web WebLogic Server

    http://weld.cdi-spec.org/documentation/#7

  • 44 NEC , Ltd. 2016

    CDI AP

    Weld

    WebLogic Server 12.1.3.0.0 []

    [] [] []

    CDI Weld

  • 45 NEC , Ltd. 2016

    CDI AP

    Weld

    [] []

    []

  • 46 NEC , Ltd. 2016

    CDI AP

    Weld

    [] org.jboss.weld=Trace []

    WebLogic Server 12.2.1.2.0

    WebLogic Server 12.1.3.0.0 [Platform Logger Levels]

  • 47 NEC , Ltd. 2016

    CDI AP

    Weld

  • 48 NEC , Ltd. 2016

    CDI AP

    Weld

    org.jboss.weld=Trace CDI 600KB

    WebLogic Server 12.2.1.2.0 STATE_PREPARED STATE_ACTIVE 1400 700KB

    CDI

    WebLogic Server 12.2.1.2.0 40 9KB

  • 49 NEC , Ltd. 2016

    CDI AP

    Weld

    Weld Weld org.jboss.weld.logging.Category.java Weld 17

    Trace

    Category

    org.jboss.weld.Bootstrap

    WebLogic Server CDI STATE_PREPARED CDI

    Weld Weld / Jersey IBM jBatch CDI

    org.jboss.weld.Version

    CDI WebLogic Server Weld

    WebLogic Server ----- -----

    org.jboss.weld.Utilities

    CDI CDI

  • 50 NEC , Ltd. 2016

    CDI AP

    Weld

    Category

    org.jboss.weld.Bean

    WebLogic Server Weld

    -----org.jboss.weldx.transaction.UserTransaction$XXXXXXXX$Proxy$_$$_Weld$Proxy$org.jboss.weld.security.Principal$XXXXXXXX$Proxy$_$$_Weld$Proxy$org.jboss.weldx.enterprise.inject.Instance$Provider$XXXXXXXX$Proxy$_$$_Weld$Proxy$

    XXXXXXXX -----

    Weld Jersey / jBatch

    CDI CDI Bean

    -----weblogic.study.BImpl$Proxy$_$$_WeldClientProxy-----

    org.jboss.weld.Servletweld-servlet ServletContainerInitializer HTTP

    org.jboss.weld.Reflection

    CDI WELD-000620

  • 51 NEC , Ltd. 2016

    CDI AP

    Weld

    Category

    org.jboss.weld.JSF

    @Named EL CDI Bean

    org.jboss.weld.Event

    @Observes CDI

    org.jboss.weld.Conversation@ConversationScoped CDI ID

    org.jboss.weld.Context

    CDI Bean BeanStore BeanStore

    RequestScoped CDI ThreadLocal -----State thread-local removed: org.jboss.weld.context.http.LazyHttpConversationContextImpl@7e4f3b94State thread-local removed: org.jboss.weld.context.http.HttpRequestContextImpl@34de8782State thread-local removed: org.jboss.weld.context.http.HttpSessionContextImpl@414b9c5e-----

  • 52 NEC , Ltd. 2016

    CDI AP

    Weld

    Category

    org.jboss.weld.El

    JSF EL

    -----WELD-001002: Looking for EL property a> WELD-001003: EL property a resolved to weblogic.study.A@272bffb7> -----

    org.jboss.weld.Resolution

    CDI -----Weld

    > [19.1.6. Bounding the cache size for resolved injection points]https://docs.jboss.org/weld/reference/latest/en-US/html/configure.html#_bounding_the_cache_size_for_resolved_injection_points

    Weld caches already resolved injection points in order to resolve them faster in the future.A separate type-safe resolver exists for beans, decorators, disposers, interceptors and observers.Each of them stores resolved injection points in its cache, which maximum size is bounded by a default value (common to all of them).-----

    https://docs.jboss.org/weld/reference/latest/en-US/html/configure.html#_bounding_the_cache_size_for_resolved_injection_points

  • 53 NEC , Ltd. 2016

    CDI AP

    Weld

    Category

    org.jboss.weld.BeanManager

    javax.enterprise.inject.spi.BeanManager CDI

    org.jboss.weld.Validator

    javax.validation.Validator CDI

    org.jboss.weld.Interceptor

    org.jboss.weld.Serialization

    CDI Bean @SessionScoped @ConversationScoped CDI

    org.jboss.weld.Configuration

    WebLogic Server CDI STATE_PREPARED

  • 54 NEC , Ltd. 2016

    CDI AP

    Weld

    org.jboss.weld.Bean / org.jboss.weld.Context

    org.jboss.weld.El / org.jboss.weld.Conversation / org.jboss.weld.Interceptor

    WebLogic Server JSF Mojarra

  • 55 NEC , Ltd. 2016

    CDI AP

    Weld .class

    Weld

  • 56 NEC , Ltd. 2016

    CDI AP

    Weld .class

    .class CLASSPATH

    WebLogic Server 12.2.1.2.0 Weld 2.3.2.Final

    Index of /groups/public/org/jboss/weld/weld-core/2.3.2.Final

    https://repository.jboss.org/nexus/content/groups/public/org/jboss/weld/weld-core/2.3.2.Final/

    https://repository.jboss.org/nexus/content/groups/public/org/jboss/weld/weld-core/2.3.2.Final/

  • 57 NEC , Ltd. 2016

    Weld .class

    Weld 2.3.2.Final

    Weld: Download

    http://weld.cdi-spec.org/download/

    CDI AP

    http://weld.cdi-spec.org/download/

  • 58 NEC , Ltd. 2016

    CDI AP

    Weld .class

    .class

    org.jboss.weld.Bean / org.jboss.weld.Context CDI

  • 59 NEC , Ltd. 2016

    CDI AP

    Weld .class

    org.jboss.weld.bean.proxy.ProxyFactory

    ProxyFactory ProxyFactory#create()

    ProxyFactory#create()

    /*** Method to create a new proxy that wraps the bean instance.** @param beanInstance the bean instance* @return a new proxy object*/

    public T create(BeanInstance beanInstance) {final T proxy = (System.getSecurityManager() == null) ? run() : AccessController.doPrivileged(this);((ProxyObject) proxy).setHandler(new ProxyMethodHandler(contextId, beanInstance, bean));return proxy;

    }

  • 60 NEC , Ltd. 2016

    CDI AP

    Weld .class

    ProxyFactory#create() ProxyFactory#createProxyClass()

    ProxyFactory#createProxyClass()

    private Class createProxyClass(String proxyClassName) throws Exception {ArraySet>(

    LifecycleMixin.class, TargetInstanceProxy.class, ProxyObject.class);addAdditionalInterfaces(specialInterfaces);// Remove special interfaces from main set (deserialization scenario)additionalInterfaces.removeAll(specialInterfaces);

    ClassFile proxyClassType = null;final int accessFlags = AccessFlag.of(AccessFlag.PUBLIC, AccessFlag.SUPER, AccessFlag.SYNTHETIC);if (getBeanType().isInterface()) {

    proxyClassType = newClassFile(proxyClassName, accessFlags, Object.class.getName());proxyClassType.addInterface(getBeanType().getName());

    } else {proxyClassType = newClassFile(proxyClassName, accessFlags, getBeanType().getName());

    }// Add interfaces which require method generationfor (Class clazz : additionalInterfaces) {

    proxyClassType.addInterface(clazz.getName());}List initialValueBytecode = new ArrayList();

  • 61 NEC , Ltd. 2016

    CDI AP

    Weld .class

    ClassFile org.jboss.classfilewriter

    org.jboss.classfilewriter

    jbossas/jboss-classfilewriter

    https://github.com/jbossas/jboss-classfilewriter/blob/master/src/main/java/org/jboss/classfilewriter/ClassFile.java

    proxyClassType

    ProxyFactory import

    import org.jboss.classfilewriter.AccessFlag;import org.jboss.classfilewriter.ClassFile;import org.jboss.classfilewriter.ClassMethod;import org.jboss.classfilewriter.DuplicateMemberException;import org.jboss.classfilewriter.code.BranchEnd;import org.jboss.classfilewriter.code.CodeAttribute;import org.jboss.classfilewriter.util.Boxing;import org.jboss.classfilewriter.util.DescriptorUtils;

    https://github.com/jbossas/jboss-classfilewriter/blob/master/src/main/java/org/jboss/classfilewriter/ClassFile.java

  • 62 NEC , Ltd. 2016

    CDI AP

    Weld .class

    ProxyFactory#createProxyClass() proxyClassType return

    ProxyFactory#createProxyClass()

    // Added by iootani fromimport org.jboss.classfilewriter.ClassField;import org.jboss.classfilewriter.ClassMethod;// Added by iootani to

    private Class createProxyClass(String proxyClassName) throws Exception {ArraySet>(

    LifecycleMixin.class, TargetInstanceProxy.class, ProxyObject.class);addAdditionalInterfaces(specialInterfaces);// Remove special interfaces from main set (deserialization scenario)additionalInterfaces.removeAll(specialInterfaces);

    ClassFile

  • 63 NEC , Ltd. 2016

    CDI AP

    Weld .class

    ProxyFactory#createProxyClass()

    ClassFile proxyClassType = null;final int accessFlags = AccessFlag.of(AccessFlag.PUBLIC, AccessFlag.SUPER, AccessFlag.SYNTHETIC);if (getBeanType().isInterface()) {

    proxyClassType = newClassFile(proxyClassName, accessFlags, Object.class.getName());proxyClassType.addInterface(getBeanType().getName());

    } else {proxyClassType = newClassFile(proxyClassName, accessFlags, getBeanType().getName());

    }

    // Added by iootani fromSystem.out.println( "********************************************************************** " );System.out.println( "ProxyClassName : " + proxyClassType.getClass().getCanonicalName() );for ( ClassField cf : proxyClassType.getFields() ) {

    System.out.println( "ClassField : " + cf.getName() );}for ( ClassMethod cm : proxyClassType.getMethods() ) {

    System.out.println( "ClassMethod : " + cm.getName() );}System.out.println( "********************************************************************** " );// Added by iootani to

    return proxyClass;}

    ClassFile

  • 64 NEC , Ltd. 2016

    CDI AP

    Weld .class

    Eclipse NetBeans IDE

    Windows

    cd /d D:osslib

    set JAVA_HOME=D:OracleJavaOraclex86-641.7.0jdk1.7.0_121

    set CLASSPATH=.set CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactscdicdi-api.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-api.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-core-impl.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-core.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-environment-common.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-probe-core.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-se-core.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-se.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-servlet-core.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-servlet.jarset CLASSPATH=%CLASSPATH%;D:osslibweld-2.3.2.Finalartifactsweldweld-spi.jar

    %JAVA_HOME%binjavac.exe -cp %CLASSPATH% ProxyFactory.java

  • 65 NEC , Ltd. 2016

    CDI AP

    Weld .class

    .class startWebLogic.cmd CLASSPATH

    CLASSPATH Windows

    @REM In order to use resource consumption management policies or to get partition's resource consumption metrics, uncomment the following JAVA_OPTIONS

    set #JAVA_OPTIONS=-XX:+UnlockCommercialFeatures -XX:+ResourceManagement -XX:+UseG1GC %SAVE_JAVA_OPTIONS%

    set SAVE_JAVA_OPTIONS=

    set CLASSPATH=%SAVE_CLASSPATH%

    set CLASSPATH=D:OracleMiddlewareOracle_Homeuser_projectsdomainscdi_domainworkdebugclass;%CLASSPATH%

    set SAVE_CLASSPATH=

  • 66 NEC , Ltd. 2016

    CDI AP

    Weld .class

    WebLogic Server CDI

    **********************************************************************ProxyClassName : org.jboss.classfilewriter.ClassFileClassField : weld_proxy_field$$$491ClassField : weld_proxy_field$$$493ClassField : weld_proxy_field$$$492ClassField : weld_proxy_field$$$494ClassField : BEAN_ID_FIELDClassField : methodHandlerClassField : constructedClassMethod : destroyClassMethod : getTargetInstanceClassMethod : getHandlerClassMethod : lifecycle_mixin_$$_preDestroyClassMethod : sayHelloClassMethod : writeReplaceClassMethod : toStringClassMethod : ClassMethod : equalsClassMethod : setHandlerClassMethod : getTargetClassClassMethod : hashCodeClassMethod : initClassMethod : lifecycle_mixin_$$_postConstructClassMethod : **********************************************************************

    @PreDestroy

    @PostConstruct

    CDI Bean sayHello()

    @PreDestroy

    @PostConstruct

  • 67 NEC , Ltd. 2016

    CDI AP

    Weld .class

    CDI Bean CDI Bean

    OSS

  • 6.

    CDI Bean

    CDI AP WELD-000072

    CDI AP NamingException

    CDI AP WELD-000321

  • 69 NEC , Ltd. 2016

    CDI Bean

    CDI

    WebLogic Server 12.1.3.0.0

    beans.xml WebLogic Server 12.2.1.2.0 class A

    EL Class A

    Interface B

  • 70 NEC , Ltd. 2016

    CDI Bean

    CDI Bean BImpl

    P21 Java EE 7 CDI

    beans.xml CDI Bean

    package weblogic.study;

    import javax.annotation.PostConstruct;

    public class BImpl implements B {@Overridepublic String execute() {

    System.out.println( "BImpl#execute called !!." );return "Hello World.";

    }

    @PostConstructpublic void init() {

    System.out.println( "BImpl was injected." );}

    }

  • 71 NEC , Ltd. 2016

    CDI Bean

    Java EE 7 CDI Bean

    /

    Java EE 7 CDI Bean beans.xml

    beans.xml Web WEB-INF annotated BImpl CDI Bean

    all CDI Bean

    annotated

    beans.xml WEB-INF / CDI Bean

    none CDI Bean

  • 72 NEC , Ltd. 2016

    CDI Bean

    CDI Bean

    class A

    package weblogic.study;

    import javax.inject.Inject;import javax.inject.Named;import javax.enterprise.context.RequestScoped;

    @RequestScoped@Namedpublic class A {

    @InjectB b;

    public String getB() {return b.execute();

    }}

    class BImpl

    package weblogic.study;

    import javax.enterprise.context.RequestScoped;

    @RequestScopedpublic class BImpl implements B {

    @Overridepublic String execute() {

    System.out.println( "BImpl#execute called !!." );return "Hello World.";

    }}

  • 73 NEC , Ltd. 2016

    CDI Bean

    CDI Bean beans.xml bean-discovery-mode all

    0 byte beans.xml WEB-INF bean-discovery-mode all

    beans.xml

  • 74 NEC , Ltd. 2016

    CDI AP WELD-000072

    CDI WebLogic Server 12.2.1.2.0

    CDI Bean - @RequestScoped

    EL hello

  • 75 NEC , Ltd. 2016

    CDI AP WELD-000072

    CDI Bean @RequestScoped HTTP @SessionScoped

    HelloImpl

    package weblogic.study;

    //import javax.enterprise.context.RequestScoped;import javax.enterprise.context.SessionScoped;

    //@RequestScoped@SessionScopedpublic class HelloImpl implements Hello {

    private int count = 0;

    @Overridepublic String sayHello() {

    // TODO Auto-generated method stubreturn "Hello World ( " + count++ + " ).";

    }}

    Test

    package weblogic.study;

    //import javax.enterprise.context.RequestScoped;import javax.enterprise.context.SessionScoped;import javax.inject.Inject;import javax.inject.Named;

    //@RequestScoped@SessionScoped@Namedpublic class Test {

    @InjectHello hello;

    public String getMessage() {return hello.sayHello();

    }}

  • 76 NEC , Ltd. 2016

    CDI AP WELD-000072

  • 77 NEC , Ltd. 2016

    CDI AP WELD-000072

  • 78 NEC , Ltd. 2016

    CDI AP WELD-000072

    @SessionScoped JSR-299

    @SessionScoped CDI Bean Serializable

    JSR-299

    6.6.3. Passivating scopes

    A passivating scope requires that:

    beans with the scope are passivation capable, and

    implementations of Contextual passed to any context object for the scope are passivation capable.

    Passivating scopes must be explicitly declared @NormalScope(passivating=true).

    For example, the built-in session and conversation scopes defined in Section 6.7, Context management for built-inscopes are passivating scopes. No other built-in scopes are passivating scopes.

  • 79 NEC , Ltd. 2016

    CDI AP WELD-000072

    Serializable implements

    CDI Bean Serializable implements

    HelloImpl

    package weblogic.study;

    import java.io.Serializable;import javax.enterprise.context.SessionScoped;

    @SessionScopedpublic class HelloImpl implements Hello, Serializable {

    private int count = 0;

    @Overridepublic String sayHello() {

    // TODO Auto-generated method stubreturn "Hello World ( " + count++ + " ).";

    }}

    Test

    package weblogic.study;

    import java.io.Serializable;import javax.enterprise.context.SessionScoped;import javax.inject.Inject;import javax.inject.Named;

    @SessionScoped@Namedpublic class Test implements Serializable {

    private static final long serialVersionUID = 1L;

    @InjectHello hello;

    public String getMessage() {return hello.sayHello();

    }}

  • 80 NEC , Ltd. 2016

    CDI AP NamingException

    CDI

    WebLogic Server 12.1.3.0.0

    WebLogic-Application-Version

    CDI

  • 81 NEC , Ltd. 2016

    CDI AP NamingException

    CDI WebLogic-Application-Version 1.1

    Version 1.1

  • 82 NEC , Ltd. 2016

    CDI AP NamingException

    CDI

  • 83 NEC , Ltd. 2016

    CDI AP NamingException

    ####

  • 84 NEC , Ltd. 2016

    CDI AP NamingException

    CDI Jersey Jersey JAX-RS Jersey CDIExtension#initialize() Weld

    NamingException

    java.lang.RuntimeException: javax.naming.NamingException: CDIExtension was previously bound from another application 'CDISampleEar1'; remaining name ''

    at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:199)at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:300)

  • 85 NEC , Ltd. 2016

    CDI AP NamingException

    Jersey CDIExtension#initialize() WebLogic Server CDI Weld Jersey

    WebLogic Server Weld Jersey verbose:class CDI

    com.oracle.injection.integration.CDIAppDeploymentExtension

    -verbose:class

    [Loaded com.oracle.injection.integration.CDIIntegrationService from file:/D:/Oracle/Middleware/Oracle_Home/wlserver/modules/com.oracle.injection.integration.weblogic.jar][Loaded com.oracle.injection.integration.CDIModuleExtensionFactory from file:/D:/Oracle/Middleware/Oracle_Home/wlserver/modules/com.oracle.injection.integration.weblogic.jar][Loaded com.oracle.injection.integration.CDIUtils from file:/D:/Oracle/Middleware/Oracle_Home/wlserver/modules/com.oracle.injection.integration.weblogic.jar][Loaded com.oracle.injection.integration.CDIAppDeploymentExtensionFactory from file:/D:/Oracle/Middleware/Oracle_Home/wlserver/modules/com.oracle.injection.integration.weblogic.jar][Loaded com.oracle.injection.integration.CDIAppDeploymentExtension from file:/D:/Oracle/Middleware/Oracle_Home/wlserver/modules/com.oracle.injection.integration.weblogic.jar][Loaded com.oracle.injection.integration.CDIAppValidationExtension from file:/D:/Oracle/Middleware/Oracle_Home/wlserver/modules/com.oracle.injection.integration.weblogic.jar]

  • 86 NEC , Ltd. 2016

    CDI AP NamingException

    CDI CDI JAX-RS Weld Jersey

  • 87 NEC , Ltd. 2016

    CDI AP NamingException

    Jersey CDIExtension#initialize() MANIFEST.MF WebLogic-Application-Version CDI JNDI CDIExtension

    JNDI com/sun/jersey/config/CDIExtension

    JNDI CDIExtension

  • 88 NEC , Ltd. 2016

    CDI AP NamingException

    CDIExtension#initialize() JNDI

    lookupExtensionInBeanManager false JNDI lookupExtensionInBeanManager true com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager true

    CDIExtension#initialize()

    private void initialize(BeanManager manager) {// initialize in a separate method because Weld creates a proxy for the extension// and we don't want to waste time initializing it

    if (!lookupExtensionInBeanManager) {try {

    InitialContext ic = InitialContextHelper.getInitialContext();if (ic != null) {

    javax.naming.Context jerseyConfigJNDIContext = createJerseyConfigJNDIContext(ic);jerseyConfigJNDIContext.rebind(JNDI_CDIEXTENSION_NAME, this);

    }} catch (NamingException ex) {

    throw new RuntimeException(ex);}

    }

  • 89 NEC , Ltd. 2016

    CDI AP NamingException

    MANIFEST.MF WebLogic-Application-Version CDI config.xml JNDI

    JNDI CDI NamingException

    CDI

    CDI MANIFEST.MF WebLogic-Application-Version

  • 90 NEC , Ltd. 2016

    CDI AP NamingException

    JAVA_OPTIONS

    CDIExtension#initialize() com/sun/jersey/config/CDIExtension JNDI Jersey CDI BeanManager NamingException

    My Oracle Support DocId 1591081.1

    -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true

  • 91 NEC , Ltd. 2016

    CDI AP WELD-000321

    @ConversationScoped

    org.jboss.weld.context.NonexistentConversationException: WELD-000321 No conversation found to restore for id 1

    at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:217)at org.jboss.weld.jsf.WeldPhaseListener.activateConversations(WeldPhaseListener.java:108)at org.jboss.weld.jsf.WeldPhaseListener.beforePhase(WeldPhaseListener.java:85)at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280).....

  • 92 NEC , Ltd. 2016

    CDI AP WELD-000321

    WELD-000321 ID WebLogic Server Google ID

    JBoss Developer

    stackoverflow> [WELD-000321 No conversation found to restore for id 3 when I refresh a page]

    http://stackoverflow.com/questions/16325686/weld-000321-no-conversation-found-to-restore-for-id-3-when-i-refresh-a-page

    github> [WELD-000321 No conversation found to restore for id 4]

    https://github.com/agoncal/agoncal-application-petstore-ee6/issues/18

    JBossDeveloper> [NonexistentConversationException: WELD-000321 No conversation found to restore for id 1]

    https://issues.jboss.org/browse/WELD-1418?_sscc=t

    JBossDeveloper> [WELD-000321: No conversation found to restore for id 1]

    https://developer.jboss.org/thread/256298

    JBossDeveloper> [Conversation-id-parameter causes WELD-000321 Exception]

    https://issues.jboss.org/browse/JBSEAM-4941

    http://stackoverflow.com/questions/16325686/weld-000321-no-conversation-found-to-restore-for-id-3-when-i-refresh-a-pagehttps://github.com/agoncal/agoncal-application-petstore-ee6/issues/18https://issues.jboss.org/browse/WELD-1418?_sscc=thttps://developer.jboss.org/thread/256298https://issues.jboss.org/browse/JBSEAM-4941

  • 93 NEC , Ltd. 2016

    CDI AP WELD-000321

    github HTTP

    HTTP

    WebLogic Server weblogic > servlet > internal > session > DebugHttpSessions HTTP

    Conversation#getTimeout() 600000 10

    github> [WELD-000321 No conversation found to restore for id 4]

    https://github.com/agoncal/agoncal-application-petstore-ee6/issues/18

    -----It's probably due to session or conversation timeout.Possible solutions :

    Deal with the exception to forward to an error pageUse a keepalive trick (Ajax call) on given pages to be sure that session / conversation doesn't timeoutRaise the timeouts to very high length and rely on EJB passivation to avoid resource exhaustion. Anyway we'll need also 1.-----

    https://github.com/agoncal/agoncal-application-petstore-ee6/issues/18

  • 94 NEC , Ltd. 2016

    CDI AP WELD-000321

    xhtml EL ManagedBean @PostConstruct Conversation#begin()

    Conversation#begin() System.out.println() ID ID

    CDI Bean

    @Named@ConversationScopedpublic class Action implements Serializable {

    @InjectConversation conversation;

    @PostConstructpublic void start() {

    conversation.begin();System.out.println( "***** cid = " + conversation.getId() );

    }

    Conversation#begin()

  • 95 NEC , Ltd. 2016

    CDI AP WELD-000321

    JBossDeveloper 1.1.12.Final2.0.0.Final Weld 2.1.0.Beta1 WELD-1418

    JBossDeveloper> [NonexistentConversationException: WELD-000321 No conversation found to restore for id 1]

    https://issues.jboss.org/browse/WELD-1418?_sscc=t

    https://issues.jboss.org/browse/WELD-1418?_sscc=t

  • 96 NEC , Ltd. 2016

    CDI AP WELD-000321

    @ConversationScoped xhtml JSF ajax / outputStylesheet

    JBossDeveloper> [NonexistentConversationException: WELD-000321 No conversation found to restore for id 1]

    https://issues.jboss.org/browse/WELD-1418?_sscc=t

    https://issues.jboss.org/browse/WELD-1418?_sscc=t

  • 97 NEC , Ltd. 2016

    CDI AP WELD-000321

    outputScript / outputStylesheet JSF

    xhtml

    #{title}

  • 98 NEC , Ltd. 2016

    CDI AP WELD-000321

    Weld 2.3.2.Final / Weld 2.1.2.Final WEB-INF/lib CDI

  • 99 NEC , Ltd. 2016

    CDI AP WELD-000321

    Weld 2.3.2.Final / Weld 2.1.2.Final

  • 100 NEC , Ltd. 2016

    CDI AP WELD-000321

    WELD-1418 JSF HTML

    Weld

  • 101 NEC , Ltd. 2016

    CDI AP WELD-000321

    WebLogic Server 12.2.1.0.0 WebLogic Server 12.2.1.0.0

    WebLogic Server 12.2.1.0.0

    WebLogic Server 12.2.1.0.0 Weld CDI 1.1 2.2.13.Final

  • 102 NEC , Ltd. 2016

    CDI AP WELD-000321

    WELD-1418

    Thread A Thread B

    A

    A ID:1 / HTTP

    BHTTP

    B

    Thread C

    C ID:1 / HTTP

    A

    HTTP

    B HTTP

    B put

    HTTP B put

    A put

    ID:1 A

    WELD-000321

  • 103 NEC , Ltd. 2016

    CDI AP WELD-000321

    xhtml HTTP JSF HTML

    JSF HTML B A HTTP A put

    HTTP

    A A HTTP put

    ServletFilter HttpSession

    A HTTP put

  • 104 NEC , Ltd. 2016

    CDI Bean Serializable implements

    Java EE 7 CDI beans.xml CDI Bean

    CDI -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true JAVA_OPTIONS

    WebLogic Server 12c R112.1.3.0.0 R212.2.1.0.0 CDI WebLogic Server CDI

  • 7.

    CDI

    @Qualifier

    @Alternative / @Priority

  • 106 NEC , Ltd. 2016

    CDI

    Oracle Enterprise Pack for Eclipse (OEPE) 12.2.1.4

    OEPE

    Oracle Enterprise Pack for Eclipsehttp://www.oracle.com/technetwork/developer-tools/eclipse/downloads/index.html

    JDK 1.8.0_102

    JDK My Oracle Support

    http://www.oracle.com/technetwork/developer-tools/eclipse/downloads/index.html

  • 107 NEC , Ltd. 2016

    CDI

    OEPE

  • 108 NEC , Ltd. 2016

    CDI

    [File] [New] [Project...] [New Project]

  • 109 NEC , Ltd. 2016

    CDI

    [New Project] [Web] [Dynamic Web Project] type filter text Dynamic [Dynamic Web Project] [Next]

    Dynamic Dynamic

    Web Project

    [Web] [Dynamic Web Project]

  • 110 NEC , Ltd. 2016

    CDI

    [New Dynamic Web Project] [Project name] [Target runtime] [New Runtime]

    CDISample Web

  • 111 NEC , Ltd. 2016

    CDI

    [New Server Runtime Environment] [Oracle] [Oracle WebLogic Server 12c R2 (12.2.1)] type filter text Oracle WebLogic Server 12c [Oracle WebLogic Server 12c R2 (12.2.1)] [Next]

    [Oracle WebLogic Server 12c R2 (12.2.1)]

    Oracle WebLogic Server 12c

    [Oracle WebLogic Server 12c R2 (12.2.1)]

  • 112 NEC , Ltd. 2016

    CDI

    [WebLogic home] WL_HOME [Finish] [Java home] WL_HOME

  • 113 NEC , Ltd. 2016

    CDI

    [New Dynamic Web Project] [Configuration] [Modify] [Project Facets]

  • 114 NEC , Ltd. 2016

    CDI

    [Project Facets] [Configuration] [JavaServer Faces v2.2 Project] [OK]

    CDI JSF JSF EL JSF

  • 115 NEC , Ltd. 2016

    CDI

    [New Dynamic Web Project] [Target runtime] [Configuration] [Finish]

    Oracle WebLogic Server 12c R2 (12.2.1)

    JavaServer Faces v2.2 Project

  • 116 NEC , Ltd. 2016

    CDI

    [Project Explorer] [Java Resources] Package / Interface / Class

  • 117 NEC , Ltd. 2016

    CDI

    [New] [Package] [New Java Package]

    [Name] [Finish]

    weblogic.study

  • 118 NEC , Ltd. 2016

    CDI

    [New] [Interface]

  • 119 NEC , Ltd. 2016

    CDI

    [Name] [Finish]

    Hello

  • 120 NEC , Ltd. 2016

    CDI

    [New] [Class]

  • 121 NEC , Ltd. 2016

    CDI

    [Name]

    [Interfaces] [Add]

    HelloImpl

  • 122 NEC , Ltd. 2016

    CDI

    [Choose Interfaces] [Matching items] [OK]

  • 123 NEC , Ltd. 2016

    CDI

    [Interfaces] [Finish]

  • 124 NEC , Ltd. 2016

    CDI

    [Interfaces]

    Test

  • 125 NEC , Ltd. 2016

    CDI

    [Project Explorer]

    Package weblogic.study

    Interface Hello CDI Bean

    Class HelloImpl CDI Bean

    Class Test CDI

  • 126 NEC , Ltd. 2016

    CDI

    package weblogic.study;

    public interface Hello {public String sayHello();

    }

    package weblogic.study;

    public class HelloImpl implements Hello {@Overridepublic String sayHello() {

    return "Hello World";}

    }

  • 127 NEC , Ltd. 2016

    CDI

    JSF EL @Named getter

    package weblogic.study;

    import javax.inject.Inject;import javax.inject.Named;

    @Namedpublic class Test {

    @InjectHello hello;

    public String getMessage() {return hello.sayHello();

    }}

  • 128 NEC , Ltd. 2016

    CDI

    @Named CDI Bean EL JSF

    JSF index.xhtml

  • 129 NEC , Ltd. 2016

    CDI

    index.xhtml

  • 130 NEC , Ltd. 2016

    CDI

    CDI Bean Test HelloImpl CDI Test HelloImpl CDI Bean CDI Bean WEB-INF beans.xml

    WebContent WEB-INF [New] [File]

  • 131 NEC , Ltd. 2016

    CDI

    [New File] [File Name] beans.xml [Finish]

  • 132 NEC , Ltd. 2016

    CDI

    [Project Explorer]

    beans.xml

    xml beans.xml

    CDI Java EE 7 CDI CDI Bean

  • 133 NEC , Ltd. 2016

    CDI

    war

    CDISample[Export] [WAR file]

  • 134 NEC , Ltd. 2016

    CDI

    [Destination] war [Browse...]

    [Finish]

    war weblogic.Deployer

  • 135 NEC , Ltd. 2016

    CDI

    http://IP:PORT/CDISample/faces/index.xhtml

    IP PORT

    Test CDI Bean getMessage()

    http://IP:PORT/CDISample/faces/index.xhtml

  • 136 NEC , Ltd. 2016

    Request @RequestScoped

    Session @SessionScoped HTTP

    Application @ApplicationScoped Web HTTP

    Conversation @ConversationScoped

    Conversation#begin() Conversation#end()JSF

    Dependent @Dependent

  • 137 NEC , Ltd. 2016

    @Request

    HTTP Keep-Alive HTTP

    Client Request

    Response

    Request

    Response

    @RequestScoped

    A

    PP

    Instance

    Instance

  • 138 NEC , Ltd. 2016

    @Session

    HTTP HTTP

    Client Request

    Response

    Request

    Response

    @SessionScopedHTTP

    A

    PP

    Instance

    HTTP

    HTTP

    Create

    Invalidate

  • 139 NEC , Ltd. 2016

    @Application

    Client

    A

    PPInstance

    Request

    Response

    Request

    Response

    Client

    A

    PP

    STATE_PREPARED

    @ApplicationScoped

    STATE_ACTIVE

  • 140 NEC , Ltd. 2016

    @Conversation

    HTTP Conversation#begin() Conversation#end()

    Request

    Client

    A

    PP

    Instance

    Request

    Response

    Request

    Response

    Request

    Response

    Request

    Response

    Request

    Response

    Conversation#begin()

    Conversation#end()

    Conversation#begin()

    Conversation#end()

  • 141 NEC , Ltd. 2016

    @Qualifier

    @Qualifier CDI

    @InjectHello hello;

    HelloImpl2 implements Hello

    HelloImpl1 implements Hello

  • 142 NEC , Ltd. 2016

    @Qualifier

    HelloImpl1

    HelloImpl1

    package weblogic.study;

    import static java.lang.annotation.ElementType.*;import static java.lang.annotation.RetentionPolicy.RUNTIME;import java.lang.annotation.Retention;import java.lang.annotation.Target;import javax.inject.Qualifier;

    @Qualifier@Retention( RUNTIME )@Target( {METHOD, FIELD, PARAMETER, TYPE} )Public @interface Hello1 {}

    HelloImpl1

    package weblogic.study;

    import javax.enterprise.context.SessionScoped;

    @Hello1public class HelloImpl1 implements Hello {}

    HelloImpl1

    javax.inject.Qualifier @Qualifier

  • 143 NEC , Ltd. 2016

    @Qualifier

    HelloImpl1 HelloImpl2

    HelloImpl2

    package weblogic.study;

    import static java.lang.annotation.ElementType.*;import static java.lang.annotation.RetentionPolicy.RUNTIME;import java.lang.annotation.Retention;import java.lang.annotation.Target;import javax.inject.Qualifier;

    @Qualifier@Retention( RUNTIME )@Target( {METHOD, FIELD, PARAMETER, TYPE} )Public @interface Hello2 {}

    HelloImpl2

    package weblogic.study;

    import javax.enterprise.context.SessionScoped;

    @Hello2public class HelloImpl2 implements Hello {}

    javax.inject.Qualifier @Qualifier

    HelloImpl2

  • 144 NEC , Ltd. 2016

    @Qualifier

    HelloImpl2

    package weblogic.study;

    import javax.enterprise.context.SessionScoped;import javax.inject.Inject;import javax.inject.Named;

    @Namedpublic class Test {

    private static final long serialVersionUID = 1L;

    @Inject@Hello2Hello hello;

    public String getHello() {return hello.sayHello();

    }}

    Hello2Impl

  • 145 NEC , Ltd. 2016

    @Alternative / @Priority

    CDI Bean

    CDI Bean

    @Inject@Hello2 @Hello1Hello hello;

    public String getHello() {return hello.sayHello();

    }

    CDI Bean

  • 146 NEC , Ltd. 2016

    @Alternative / @Priority

    HellpImpl HelloImplDev

    @InjectHello hello;

    HelloImplTest implements Hello

    HelloImpl implements Hello

    HelloImplDev implements Hello

  • 147 NEC , Ltd. 2016

    @Alternative / @Priority

    CDI Bean Bean Bean

    @CDI Bean

    package weblogic.study;

    import javax.enterprise.context.RequestScoped;

    @RequestScopedpublic class HelloImpl implements Hello {

    @Overridepublic String sayHello() {

    // TODO Auto-generated method stubreturn "Hello World (Production).";

    }

    }

    Bean

    package weblogic.study;

    import javax.annotation.Priority;import javax.enterprise.context.RequestScoped;import javax.enterprise.inject.Alternative;

    @Alternative@Priority( 1000 )@RequestScopedpublic class HelloImplDev implements Hello {

    @Overridepublic String sayHello() {

    // TODO Auto-generated method stubreturn "Hello World (Development).";

    }

    }

  • 148 NEC , Ltd. 2016

    @Alternative / @Priority

    @Alternative Bean Bean

    @Priority Bean

    Java EE 7 Java EE 6

    Java EE 6 beans.xml Bean

    Bean CDI Bean

    beans.xml

    weblogic.study.HelloImplDev

  • 149 NEC , Ltd. 2016

    @Alternative / @Priority

    Bean CDI Bean

  • 150 NEC , Ltd. 2016