小编Mic*_*urt的帖子

Spring @Transactional on @Bean声明而不是类Implementation

我想从我的Spring @Configuration类配置"事务性"bean,而不是使用它来注释类实现本身@Transactional.

有点像旧学校的方式,从XML文件配置事务建议,但不需要对我的类/方法名称的String引用来创建切入点.

原因是bean实现在另一个代码库中,它所属的模块不依赖于Spring.阅读:我没有触及那个bean的源代码,只是实例化它.该类是final,无法扩展它以将Spring注释添加到子类.假设所有方法都必须是事务性的,为简单起见.

bean实现:

/** This class has no Spring dependency... */
// @Transactional <- which means I can't use this here
public final class ComplexComponentImpl implements ComplexComponent {

    private SomeRepository repo;

    public ComplexComponentImpl(SomeRepository repository) { this.repo = repository }

    public void saveEntities(SomeEntity e1, SomeEntity e2) {
        repo.save(e1);
        throw new IllegalStateException("Make the transaction fail");
    }
Run Code Online (Sandbox Code Playgroud)

我想在我的配置类中做什么(哪些在我的单元测试中不起作用):

@Configuration
@EnableTransactionManagement
public class ComplexComponentConfig {

    @Bean
    @Transactional // <- Make the bean transactional here
    public ComplexComponent complexComponent() {
        return …
Run Code Online (Sandbox Code Playgroud)

java spring jpa transactions

7
推荐指数
1
解决办法
3546
查看次数

使用环境变量设置Hystrix超时

要更改Hystrix的默认请求超时(1000毫秒),必须设置以下属性: hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000

相应的环境变量是什么?

我想在我最喜欢的云平台上"调整"超时,而不首先触及源代码.我很确定这个不起作用:HYSTRIX_COMMAND_DEFAULT_EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS=2000


编辑:Spring Cloud Camden/Spring Boot 1.4发现问题.

hystrix spring-cloud spring-cloud-netflix

4
推荐指数
2
解决办法
7076
查看次数