运行项目

时间:2017-07-25 03:02:45

标签: java spring

public interface DictDao {
   void updateUserInfo(UserUser userUser);
}


@Repository(value = "dictDao")
public class DictDaoImpl<K extends Serializable, V extends Serializable> implements DictDao {

    @Autowired
    protected RedisTemplate<K, V> redisTemplate;

    @Override
    public void updateUserInfo(final UserUser userUser) {
    }
}

服务

@Service("userUserService")
public class UserUserServiceImpl implements UserUserService{

    @Resource
    private UserUserDao userUserDao;

    @Override
    public UserUser insertByHugId(String hugId, String partnerType) {
        UserUserDto dto = new UserUserDto();
        dto.setHgId(hugId);
        UserUser userUser = userUserMapper.select(dto);
        userUserDao.add(userUser,partnerType);
        return userUser;
    }
}

Spring配置 [在此输入图像说明] [5] [在此处输入图像说明] [6]

我的测试

public class UserUserServiceImplTest {

    private ClassPathXmlApplicationContext context;

    private UserUserService userUserService;

    @Before
    public void setUp() throws Exception {
        context = new ClassPathXmlApplicationContext("classpath:spring/spring-config.xml");
        userUserService = (UserUserService)context.getBean("userUserService");
    }

    @Test
    public void insertByHugId() throws Exception{
        userUserService.insertByHugId("LN13177109","52");
    }
}
运行测试时,

出现此异常: org.springframework.context.annotation.ConflictingBeanDefinitionException:bean类[com.lanniuh.manage.dao.user.redis.hug.UserUserDao]的注释指定bean名称'userUserDao'与同名的现有非兼容bean定义冲突和班级[com.lanniuh.manage.dao.user.redis.hug.impl.UserUserDaoImpl]

请帮助我,非常有帮助。

1 个答案:

答案 0 :(得分:0)

您可以通过完全删除自动装配并通过应用程序上下文和getBean()方法创建对它的引用来访问bean来解决此问题。

或者您可以在所有类上使用注释,并在ApplicationContaxt.xml中使用以下代码:

<context:annotation-config />
<context:component-scan base-package="com.test.package.*" />

并使用@Autowired