我的Java EE应用程序使用crawler4j使用下面的代码开始抓取:EJB不注射
CrawlConfig config = new CrawlConfig();
config.setCrawlStorageFolder("C:/crawler4j_storage");
PageFetcher pageFetcher = new PageFetcher(config);
RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);
controller.start(Crawler.class, 1);
的EJB注入在Crawler.class:
@Stateless
@LocalBean
public class Crawler extends WebCrawler {
@Inject private SeedFacadeLocal seedEJB;
public void doSomething() {
seedEJB.findAll(); // gives the NullPointerException
}
我的猜测是,它有与Crawler.class作为参数传递的方式有关。 SeedFacadeLocal是一个拥有@Stateless bean实现的@Local bean接口。我在许多其他地方注入了这个bean,并且它工作正常。
我认为通过使用“controller.start(Crawler.class,1)”开始爬网会导致Crawler.class成为POJO而不是EJB。因此,Crawler.class中的注释被忽略。
什么? (a)您的第一行代码无效;这应该是一个变量的分配? (b)这是什么'SeedFacadeLocal'类型? (c)你为什么使用'@Inject'和一个看起来像EJB的变量?如果你要问一个问题,至少问一个有意义的问题! –
我会更新,但我认为找到解决方案并不重要 – BigJ
细节不会。你可以写'CrawlController控制器; controller.start(Crawler.class,1);'。但是当我看到一个包含无法编译的代码的问题时,不可能说出它的真正含义。 –