Injecting EJB 3 into Spring Bean

混江龙づ霸主 提交于 2019-11-28 00:10:56

We have found quite nice and simple solution. Into spring configuration file one has to put:

<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
    <property name="alwaysUseJndiLookup" value="true" />
</bean>

And that enables spring to search for the beans annotated with @Resource in JNDI. So now one can do:

@Resource(mappedName = MyBean.JNDI_NAME)
private MyBean myBean;
Tomasz Nurkiewicz

Are you aiming to get rid of XML or to have JNDI name in annotation? If the former, I haven't tested it, but should work:

@Configuration
public class EjbCfg {

    @Bean
    public JndiObjectFactoryBean myBean() {
        JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
        factory.setJndiName(MyBean.JNDI_NAME);
        return factory;
    }

}

Now you can simply inject:

@Autowired
private MyBean myBean;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!