@EJB工作,而@Inject失败



我最近用Glassfish开发了一个应用程序,开发非常顺利,现在用JBoss我正试图做同样的事情,但由于各种问题而减慢速度,例如:@EJB工作,但@Inject失败。我还没有一个花哨的类,我只注入了一个Singleton Startup类和一个简单的无状态类,令我惊讶的是,注入不起作用。这是我的类:

package com.czetsuya.dropship;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
@Startup
public class StartupListener {
    private Logger log = LoggerFactory.getLogger(StartupListener.class);
    @EJB
    private TestService testService;
    public StartupListener() {
    }   
    @PostConstruct
    private void init() {
        testService.test();
        log.debug("startup");
    }
}

服务类:

package com.czetsuya.dropship;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
@Stateless
@LocalBean
public class TestService {
    public TestService() {
    }
    public void test() {
        System.out.println("run");
    }
}

另一件事是,如果我用下面的生产者注入我的记录器,它也不工作,并抛出:

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field] @Inject private com.czetsuya.dropship.StartupListener.log]

日志生成器:

@Produces
Logger createLogger(InjectionPoint injectionPoint) {
    return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}

请注意,我的ejb和war项目中有beans.xml。

My beans.xml文件:

<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/beans_1_0.xsd"></beans>

嗯,我的坏,似乎是一个腐败的构建,之后我项目清洁和maven清洁和更改bean .xml内容:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="urn:java:ee" xmlns:security="urn:java:org.jboss.seam.security" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd"></beans>

注入现在工作。

最新更新