Hi,
I created a JNDI object provider to directly inject JNDI resources into
managed services :
public class JNDIObjectProvider implements ObjectProvider {
@Override
public <T> T provide(Class<T> objectType, AnnotationProvider
annotationProvider, ObjectLocator locator) {
JNDIResource annotation =
annotationProvider.getAnnotation(JNDIResource.class);
if (annotation == null) {
return null;
}
String name = annotation.value();
try {
Context ctx = new InitialContext(); T resource =
(T) ctx.lookup(name);
return resource;
} catch (NamingException e) {
throw new RuntimeException("JNDI lookup failed for name: " +
name, e);
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface JNDIResource {
String value();
}
Used in a service :
@Inject @JNDIResource("java:comp/env/jdbc/myDataSource")
private DataSource dataSource;
Hope it can help
Regards,
<http://www.financeactive.com/>
Guillaume Bodet
Directeur de la Technologie - CTO
T. +33 177 721 613
M. +33 620 888 665
www.financeactive.com <http://www.financeactive.com/>
<https://twitter.com/#!/Financeactive>
<http://www.linkedin.com/company/finance-active>
<http://fr.viadeo.com/fr/profile/finance.active>
<http://fr-fr.facebook.com/pages/Finance-active/426171734065585>
P Avant d¹imprimer, pensez à l¹environnement
Ce message et toutes les pièces jointes sont établis à l'intention
exclusive de ses destinataires et sont confidentiels. L'internet ne
permettant pas d'assurer l'intégrité de ce message, Finance active décline
toute responsabilité au titre de ce message, dans l'hypothèse où il aurait
été intercepté ou modifié.
Le 21/06/12 07:01, « cablepuff » <[email protected]> a écrit :
>Thanks.
>
>It works.
>
>I created
>
>public static DataSource buildMyDataSource() {
> // ... implemenation.
>}
>
>then inject the code using @Local @Service("myDataSource") DataSource
>dataSource like you suggested.
>
>
>
>
>--
>View this message in context:
>http://tapestry.1045711.n5.nabble.com/AppModule-using-injected-service-in-
>ContributeWebSecurityManager-tp5713989p5714000.html
>Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]