zoukankan      html  css  js  c++  java
  • STS中不同包但相同类名引起的问题:A component required a bean of type 'javax.activation.DataSource' that could not be found

    1. 问题输出:

    APPLICATION FAILED TO START
    ***************************

    Description:

    A component required a bean of type 'javax.activation.DataSource' that could not be found.


    Action:

    Consider defining a bean of type 'javax.activation.DataSource' in your configuration.

    2. 源码:

    package boat.db.db;

    import javax.activation.DataSource
    import org.springframework.beans.BeansException;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    import org.springframework.stereotype.Component;

    @Component
    public class DataSourceShow implements ApplicationContextAware {
    @Autowired
    ApplicationContext applicationContext = null;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
    DataSource dataSource = applicationContext.getBean(DataSource.class);
    System.out.println("----------------------------------------------");
    System.out.println(dataSource.getClass().getName());
    System.out.println("----------------------------------------------");
    }

    }

    解决:

    起初以为是配置问题,增加了依赖项,并不起作用。

    后仔细研究原例子发现,DataSource类不是 javax.activation.DataSource,而是import javax.sql.DataSource

    改了后,正常运行

    总结:

    java有很多依赖项中有很多同名,但不同包的类型,所以使用时要注意

  • 相关阅读:
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作
    爬虫大作业
    熟悉常用的HDFS操作
    数据结构化与保存
    获取全部校园新闻
    爬取校园新闻首页的新闻的详情,使用正则表达式,函数抽离
    NPOI的excel导出1
    DbHelperSQL帮助类
    C# mvc导出excel
  • 原文地址:https://www.cnblogs.com/myboat/p/11493215.html
Copyright © 2011-2022 走看看