SpringBoot 異常 java.io.FileNotFoundException: class path resource [com/sxw/springbootproducer/mappin

2019-11-08 17:23:24.446 ERROR 215864 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rabbitOrderSender': Unsatisfied dependency expressed through field 'brokerMessageLogMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brokerMessageLogMapper' defined in file [E:\學習\java\項目學習\springboot-rabbitmq\springboot-producer\target\classes\com\sxw\springbootproducer\mapper\BrokerMessageLogMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/sxw/springbootproducer/config/database/MybatisDataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.RuntimeException: java.io.FileNotFoundException: class path resource [com/sxw/springbootproducer/mapping/] cannot be resolved to URL because it does not exist


 

問題: 找不到URL指定的文件

出錯位置:

這個位置找不到URL對應的文件

進一步分析,通過 https://github.com/suxiongwei/springboot-rabbitmq/issues/1

得到解決辦法:

報 xml找不到。
可在:springboot-produce.pom 文件內添加如下代碼:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>

爲什麼這麼做可以? 

先看rescources 標籤的作用 https://blog.csdn.net/qq_36881106/article/details/88664898

從而得到錯誤原因:

由於沒有配置resources 所以不會打包該路徑下的文件到classpath, 然後就沒有mapping這個文件夾,所以dataSource找不到URL,就報錯。

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章