2013-05-31 27 views
2

我正在使用焊縫1.0。這裏是我的情況:我有一個類實例化它試圖實例化一個類StartupShutdown一個焊接容器:焊縫構造函數中的焊接注入:無法解析任何類型的beans

public static void main(String[] args) { 
    WeldContainer weld; 
    weld = new Weld().initialize(); 

    StartupShutdown startupShutdown = weld.instance().select(StartupShutdown.class).get(); 
} 

這裏是我的StartupShutdown類:

public class StartupShutdown { 

    @Inject 
    public StartupShutdown(LoggingFileHandler loggingFileHandler) { 
    } 
} 

我得到這個異常:

Exception in thread "main" org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve any beans for Types: [class fr.easycompany.easywrite.processes.StartupShutdown]; Bindings: [QualifierInstance{annotationClass=interface javax.enterprise.inject.Default, values={}, hashCode=2062316647}] 
    at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:728) 
    at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:102) 
    at fr.easycompany.easywrite.EasyWrite.main(EasyWrite.java:18) 

當我刪除StartupShutdown構造函數中的參數時,它可以工作。

只是爲了信息,這是我LoggingFileHandler

public class LoggingFileHandler extends FileHandler { 

    @Inject 
    public LoggingFileHandler(LoggingFormatter formatter) throws IOException, SecurityException { 
     super(""); 
     this.setFormatter(formatter); 
    } 
} 

有什麼不對這個參數在我的構造函數?

回答

2

對我感到羞恥!我只是把LoggingFileHandler意外地放在我的src/test/java中。現在工作正常。這就是爲什麼無法找到Bean。