相关疑难解决方法(0)

春天自我注射

我尝试使用Spring 3.x的以下代码失败了BeanNotFoundException,它应该根据我之前问过的问题的答案 - 我可以使用Spring注入相同的类吗?

@Service
public class UserService implements Service{
    @Autowired
    private Service self;
}
Run Code Online (Sandbox Code Playgroud)

自从我用Java 6尝试这个以来,我发现以下代码工作正常:

@Service(value = "someService")
public class UserService implements Service{
    @Resource(name = "someService")
    private Service self;
}
Run Code Online (Sandbox Code Playgroud)

但我不明白它如何解决循环依赖.

编辑:
这是错误消息.OP在其中一个答案的评论中提到它:

由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型为[com.spring.service.Service]的匹配bean:期望至少有一个bean可以作为此依赖项的autowire候选者.依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

java spring dependency-injection ioc-container

58
推荐指数
2
解决办法
3万
查看次数

需要Spring Transaction传播,REQUIRES_NEW

在下面的代码方法doService1()更新正确的SQL但doService2()sql有一些问题,但是当我调用doService()它必须提交doService1()更新到DB,即使doService2()有一个sql exception因为doService2() 有一个REQUIRES_NEW Propagation类型,但当我doService1()没有这个更新不提交数据库..

@Service public class DbClass {

      static Logger log = Logger.getLogger(
              DbClass.class.getName());

@Autowired
private DataSource dataSource;

@Transactional(propagation=Propagation.REQUIRED)
public void doService(){
    doService1();
    doService2();
}

@Transactional(propagation=Propagation.REQUIRED)
public void doService1(){
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "  update BATCHJOBSTATUS set PROCESSINGDATE = '20130322'  " ;
    int rowCount1 =  jdbcTemplate.update(sql);
    System.out.println(" rowCount1 >" + rowCount1);
}

@Transactional(propagation=Propagation.REQUIRES_NEW)
public void doService2(){
    JdbcTemplate jdbcTemplate …
Run Code Online (Sandbox Code Playgroud)

spring transactions propagation

2
推荐指数
1
解决办法
2万
查看次数