質問

I have an external String resource declared into server (either Jboss 7.1.1 or WAS 8) JBoss :

...
<subsystem xmlns="urn:jboss:domain:naming:1.1">
  <bindings>
     <simple name="jboss/resources/foovalue" value="helloworld"/>
  </bindings>
</subsystem>
...

I can get it nicely from my war module like this :

@ManagedBean
@RequestScoped
public class Footest
...
@Resource(name = "foovalue")
private String externalFoo;
...

but if I try to get it from an EJB module (Maven dependency as EJB type) like

@Stateless
public class FooServiceImpl implements FooServiceLocal
...
    @Resource(name = "foovalue")
    private String externalFoo;
...

I got a null value !

did I missed something ?

役に立ちましたか?

解決

Nikos pointed me to the right solution : must have a ejb-jar.xml into classpath (src\main\resources\META-INF)

 <?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
    version="3.1">

        <enterprise-beans>
            <session>
                <ejb-name>FooServiceImpl </ejb-name>
                <resource-ref>
                    <res-ref-name>foovalue</res-ref-name>
                    <res-type>java.lang.String</res-type>
                </resource-ref>
            </session>
        </enterprise-beans>
    </ejb-jar>

Note that if you use WAS 8.x you must declare the resource into a ibm-ejb-jar-bnd.xml file :

<?xml version= "1.0" encoding="UTF-8"?>
<ejb-jar-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd" version="1.0">

    <session name="FooServiceImpl" >
        <resource-ref name="foovalue" binding-name="foovalue"/>
    </session>
</ejb-jar-bnd>

The reference foo-value is declared into WAS 8 like :

Open administrative console, go into Environment > Manage Name Space Bindings. Select scope and

  • Binding type = String
  • Binding identifier = foovalue
  • Name in name space= foovalue
  • String value = helloworld
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top