How to configure Glassfish to inject String in EJB3.1?

I want to do something like that (Very basic...) :

  @Resource(lookup = "my/jndi/name")
  private String someString;

And the glassfish console isn't clear about how to configure a jndi String resource named "my/jndi/name".

Upvotes: 1

Views: 1113

Answers (2)

LightGuard
LightGuard

Reputation: 5378

You might also want to take a look at the Configuration stuff in DeltaSpike.

Upvotes: 1

If you want to do something like that :

@Resource(lookup = "your/jndi/name")
private String someString;

You can use the glassfish console and add a custom resource :

Custom String Value with glassfish

Note that you must add a property with "value" as name.

And here is the corresponding glassfish-resource.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
  "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
  "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <custom-resource jndi-name="your/jndi/name" res-type="java.lang.String" factory-    class="org.glassfish.resources.custom.factory.PrimitivesAndStringFactory">
        <property name="value" value="your value"></property>
    </custom-resource>
</resources>

Upvotes: 3

Related Questions