首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@Transactional显示问题

@Transactional显示问题
EN

Stack Overflow用户
提问于 2018-09-10 15:56:41
回答 1查看 42关注 0票数 1

我是spring的新手,我刚刚开始了一个基于java配置的项目,在构建我的项目时,我从Tomcat日志中得到了这样的消息:

代码语言:javascript
复制
SEVERE: Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'countryController': Unsatisfied dependency expressed through field 'countryService'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'countryService' is expected to be of type 'com.djamel.service.CountryService' but was actually of type 'com.sun.proxy.$Proxy37'

这是我的CountryService课程:

代码语言:javascript
复制
@Service
public class CountryService implements Services<Country>{

    @Autowired
    CountryDao countryDao;

    @Autowired
    CityDao cityDao;

    ...

    @Transactional
    public Long add(Country country) {

       Long key = countryDao.add(country);

       if(!country.getCities().isEmpty()){
          for (City city : country.getCities()) {
              cityDao.add(key, city);
          }         
       }

       return (long) 1;
    }

    ...

}

这是我的Config课程:

代码语言:javascript
复制
@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages = "com.djamel")
public class AppConfig {

    @Bean
    public DataSource dataSource() {
        ...
    }

    @Bean
    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
        ...
    }   
}

请问,我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-10 16:30:46

您没有发布控制器代码或服务接口。但是,从堆栈跟踪来看,Spring试图使用接口的代理来满足依赖关系。在控制器中向您的服务添加一个限定符应该会修复它。类似于:

代码语言:javascript
复制
public class CountryController{
..
@Autowired @Qualifier("CountryService")
private Services<Country> countryService;
..
..
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52261514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档