2012-09-30

CDI @Produces not working?

I deployed my application to JBoss AS 7.1.1.Final and realised that my @Produces annotations were not really producing... But they were working fine with Arquillian. It was my programming error.

This does not work

@ApplicationScoped
public class TrackMappersFactory {

    @EJB
    private AudiobookMapper audiobookMapper;
    @EJB
    private PodcastMapper podcastMapper;
    @EJB
    private SongMapper songMapper;
    @EJB
    private VideoMapper videoMapper;

    @Produces
    @AggregateMapper
    public Map<Class<? extends TrackTo>, TrackMapper<? extends TrackTo>> getAggregateTrackMapper() {
The reason why is simple, this class is not detected by the container because it's not an EJB. The solution is to make it a @Singleton bean instead.

This works

@Singleton
public class TrackMappersFactory {

    @EJB
    private AudiobookMapper audiobookMapper;
    @EJB
    private PodcastMapper podcastMapper;
    @EJB
    private SongMapper songMapper;
    @EJB
    private VideoMapper videoMapper;

    @Produces
    @AggregateMapper
    public Map<Class<? extends TrackTo>, TrackMapper<? extends TrackTo>> getAggregateTrackMapper() {
Here is the diff for this change.

3 comments:

  1. I feel good about your share. I am so happy to see your blog. Do My Homework Thank you for sharing it with us.

    ReplyDelete
  2. Very much like your beloved football crew, you won't ever walk alone when you want task help in liverpool. Our expert task aides will give you all the essential Assignment Done For You help according to your guidelines and will offer extra work to guarantee your task gets appropriate appreciation.

    ReplyDelete
  3. This is it! You can use this service and be raddy for help! Enjoy your life and be rady for this! Check this personal statement writing help help adn go on! Enjoy your life adn be rady for wins! Enjoy your life and be ready for you! Good luck!

    ReplyDelete