Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在jboss 7上使用@EJB注入EJB 3_Java_Maven_Jakarta Ee_Ejb_Jboss7.x - Fatal编程技术网

Java 无法在jboss 7上使用@EJB注入EJB 3

Java 无法在jboss 7上使用@EJB注入EJB 3,java,maven,jakarta-ee,ejb,jboss7.x,Java,Maven,Jakarta Ee,Ejb,Jboss7.x,Jboss日志:- JBAS015876:开始部署“medmark.war” 17:33:56948 INFO[org.jboss.as.ejb3.deployment.processors.ejbndibingsdeploymentunitprocessor](MSC服务线程1-8)部署单元部署“medmark.war”中名为HelloService的会话bean的JNDI绑定如下: I am trying to use @EJB annotation to call a stateless

Jboss日志:-

JBAS015876:开始部署“medmark.war” 17:33:56948 INFO[org.jboss.as.ejb3.deployment.processors.ejbndibingsdeploymentunitprocessor](MSC服务线程1-8)部署单元部署“medmark.war”中名为HelloService的会话bean的JNDI绑定如下:

I am trying to use @EJB annotation to call a stateless bean. When I print the value of the reference, it is NULL I a'm running on jboss 7. Please help me I have traied all possipole configruation, If I missed any thing please notify me. find the full stack below                     
JSFbean:

    @Stateless
    public class HelloService{

        public HelloService(){

        }
        public String sayHello() {
            return "Hello EJB";
        }
    }

考虑一下:您正在-constructor-中使用注入bean。但是构造函数是第一个被调用的东西,所以当然在那一点上还没有注入任何东西

而是在构建后的方法中进行

    @ManagedBean
    @RequestScoped
    public class HelloBean {

        @EJB
        HelloService service;

        private String testString;

        public HelloBean(){
            testString = service.sayHello();
        }
        public String getTestString() {
            return testString;
        }

        public void setTestString(String testString) {
            this.testString = testString;
        }

    }

谢谢Gimby,我尝试过使用@PostConstruct,但没有任何改变?!!我必须实现本地接口吗?因为JEE6不再需要了。很抱歉,我不知道您所提供的还可能缺少什么。@IbrahimQandeel您仍然有问题的原因是什么?我使用了@EJB HelloService Local service;而不是HelloService服务;清理并建造项目啊,好的,是的。如果给bean一个本地接口,那么就必须使用它。但是自从JEE6以来,你不再被迫给它任何类型的接口。
    @ManagedBean
    @RequestScoped
    public class HelloBean {

        @EJB
        HelloService service;

        private String testString;

        public HelloBean(){
            testString = service.sayHello();
        }
        public String getTestString() {
            return testString;
        }

        public void setTestString(String testString) {
            this.testString = testString;
        }

    }
@ManagedBean
@RequestScoped
public class HelloBean {

    @EJB
    HelloServiceLocal service;

    private String testString;

    public HelloBean(){
    }

    @PostConstruct
    public void init(){
      testString = service.sayHello();
    }