7 Replies Latest reply on Jan 24, 2020 9:57 PM by rhn-support-rhsilva

    Datasource resource injection in JBoss 6 using CDI

    mikaelbeermann

      Hi,

       

      I'm building a CDI based project with JBoss 6, but I can't get the injection of datasources to work. If I do a manual JNDI-lookup the datasource is found whitout any problem. Using the @Resouce annotation, the datasource remains null, but there is no exceptions visible in the log file (excapt for a NullPointerException when trying to use the datasource).

       

      This works:

      Context context = new InitialContext();

      defaultDS = (DataSource) context.lookup("java:MySqlDS");

       

      but this doesn't work:

      @Resource(mappedName="java:MySqlDS")

      DataSource defaultDS;

       

      and this doesn't work either:

      @Resource(name="java:MySqlDS")

      DataSource defaultDS;

       

      First I thought it was som kind of naming error, but since no exception shows up, I think it looks more like the @Resource annotation doesn't work at all.

      Are there any  known conflict with the Resource injectionns in JBoss 6? Does anyout have a clue of what can be wrong?

       

      /Mikael