java太难了!
2021-07-06 19:51
采纳率: 93.9%
浏览 27
已采纳

大lao进来看看 Failed to load ApplicationContext

报错

class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Detected cyclic loading of class path resource [applicationContext.xml] - check your import definitions!

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">


    <import resource="classpath:applicationContext.xml"/>

    <bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${driverClassName}"/>
        <property name="url" value="${druid.url}"/>
        <property name="username" value="${druid.username}"/>
        <property name="password" value="${druid.password}"/>
    </bean>

    <bean id="factory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
        <property name="dataSource" ref="druidDataSource"></property>
    </bean>

    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.vx202158.mapper"></property>
    </bean>

</beans>


test1

package mybatisPlusTest;

import com.vx202158.mapper.AdminMapper;
import com.vx202158.pojo.Admin;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class test1 {
    @Autowired
    private AdminMapper adminMapper;

    @Test
    public void test1(){
        List<Admin> admins = this.adminMapper.selectList(null);

        for (Admin admin : admins) {
            System.out.println("admin = " + admin);
        }

    }
}

img

![img](觉没问题啊 我去

https://img-mid.csdnimg.cn/release/static/image/mid/ask/72043127552610.0764060066627783.png)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 404警告 2021-07-06 20:05
    已采纳

    头部换成@ContextConfiguration(locations = {"classpath:applicationContext.xml"}试试
    查看是否是test版本太低

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题