小编Cur*_*rge的帖子

bean 实例化失败:指定的类是一个接口

我在创建用于依赖注入的 bean 时遇到问题。这是场景。

我正在处理 MongoDB 存储库,我还创建了一个使用它的类。我正在尝试实例化两者的 bean 实例。

MongoDB 存储库:

@Repository
public interface ProductGlobalTrendRepository extends MongoRepository<ProductGlobalTrend,String>{
    public ProductGlobalTrend findByPid(@Param("pId") String pId);
}
Run Code Online (Sandbox Code Playgroud)

使用它的类:

@Service
@Scope("singleton")
public class ProductTrendService {

    @Autowired
    @Qualifier("productGlobalTrendRepo")
    ProductGlobalTrendRepository productGlobalTrendRepo;

    public ProductTrendService() {
        super();
    }   

    public void setProductGlobalTrendRepo(
            ProductGlobalTrendRepository productGlobalTrendRepo) {
        this.productGlobalTrendRepo = productGlobalTrendRepo;
    }

    public ProductTrendService(ProductGlobalTrendRepository productGlobalTrendRepo) {
        super();
        this.productGlobalTrendRepo = productGlobalTrendRepo;
    }
}   
Run Code Online (Sandbox Code Playgroud)

spring 的 bean 配置 xml 具有以下条目:

<bean id="productTrendService" class="com.api.services.ProductTrendService"> </bean>
<bean id="productGlobalTrendRepo" class="com.mongodb.repository.ProductGlobalTrendRepository"> </bean>
Run Code Online (Sandbox Code Playgroud)

以下是我收到的错误:

19428 [localhost-startStop-1] 警告 org.springframework.web.context.support.AnnotationConfigWebApplicationContext - 上下文初始化期间遇到异常 - …

spring javabeans mongodb

7
推荐指数
1
解决办法
3万
查看次数

log4j2:异步记录器未启动

我最近将我的应用程序升级为使用log4j2。我正在尝试利用其异步记录器功能。但是,看起来它不是在创建一个。根据Log4j Async config,它说,

  1. 要使所有记录器异步,请将干扰器jar添加到类路径,并将系统属性Log4jContextSelector设置为org.apache.logging.log4j.core.async.AsyncLoggerContextSelector。我还在log4j.xml中设置status =“ trace”,以查看它是否配置并实例化了异步记录器。但是看起来好像失败了。

2017-01-25 01:58:30,799主要TRACE重新注册上下文(1/1):'AsyncContext @ 18b4aac2'org.apache.logging.log4j.core.async.AsyncLoggerContext@6bf08014 2017-01-25 01:58:30,800主TRACE正在注销,但未找到与'org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2'相匹配的MBean,2017-01-25 01:58:30,800主TRACE正在注销,但未找到与'org.apache.logging.log4j2相匹配的MBean: type = AsyncContext @ 18b4aac2,component = StatusLogger'2017-01-25 01:58:30,800主TRACE正在注销,但未找到与'org.apache.logging.log4j2匹配的MBean:type = AsyncContext @ 18b4aac2,component = ContextSelector'2017-01 -25 01:58:30,801主要TRACE正在注销,但未找到与'org.apache.logging.log4j2相匹配的MBean:type = AsyncContext @ 18b4aac2,component = Loggers,name ='2017-01-25 01:58:30,801主TRACE正在注销,但未找到与'org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = Appenders,name = ' 匹配的MBean: '2017-01-25 01:58: 30,801个主要的TRACE注销,但未找到匹配'org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = AsyncAppenders,name = '2017-01-25 01:58:30,801个主要的TRACE正在注销,但未找到匹配的MBean org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = AsyncLoggerRingBuffer'2017-01-25 01:58:30,802主要TRACE正在注销,但未找到与'org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2匹配的MBean ,component =记录器,名称=,subtype …

asynchronous log4j2

5
推荐指数
2
解决办法
9311
查看次数

Java:基于时间的线程锁定

我正在寻找一种方法在java中,通过它我们可以实现基于时间的java线程锁定或者可能是基于时间的中断.考虑一下.

一个java线程调用以下函数,

private DATA getData() {
   DATA data;
   synchronized(dataLock) {
       data = fetchData()
   }
   return data
}
Run Code Online (Sandbox Code Playgroud)

现在假设对fetchData()的调用挂起,不返回.有没有办法在这个锁(dataLock)上超时,或者中断这个线程?

java multithreading

0
推荐指数
1
解决办法
94
查看次数