小编use*_*476的帖子

@Retryable在Spring引导应用程序中由集成测试触发时不进行重试

我在SpringBoot应用程序的Service中有一个简单的方法.我使用@Retryable为该方法设置了重试机制.
我正在尝试对服务中的方法进行集成测试,并且在方法抛出异常时不会发生重试.该方法只执行一次.

public interface ActionService { 

@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000))
public void perform() throws Exception;

}



@Service
public class ActionServiceImpl implements ActionService {

@Override   
public void perform() throws Exception() {

   throw new Exception();
  } 
}



@SpringBootApplication
@Import(RetryConfig.class)
public class MyApp {

public static void main(String[] args) throws Exception {
    SpringApplication.run(MyApp.class, args);
  }
}



@Configuration
@EnableRetry
public class RetryConfig {

@Bean
public ActionService actionService() { return new ActionServiceImpl(); }

}



@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration( classes= {MyApp.class}) 
@IntegrationTest({"server.port:0", "management.port:0"})
public …
Run Code Online (Sandbox Code Playgroud)

java spring spring-retry spring-boot

5
推荐指数
1
解决办法
8470
查看次数

删除没有正则表达式的java代码中的所有注释

我正在做一个家庭作业,我需要读取一个java源文件并删除它的所有注释.其余的造型应该保持不变.

我已经使用正则表达式完成了任务.

但我希望在不使用正则表达式的情况下完成同样的工作.

示例输入

// My first single line comment

class Student {

  /* Student class - Describes the properties
  of the student like id, name */

  int studentId; // Unique Student id
  String studentName; // Name of the student
  String junk = "Hello//hello/*hey";

} // End of student class
Run Code Online (Sandbox Code Playgroud)

结果

class Student {

  int studentId;
  String studentName;
  String junk = "Hello//hello/*hey";

}
Run Code Online (Sandbox Code Playgroud)

我的想法是阅读每一行

1)检查前两个字符

  • 如果以// ==>开头,则删除该行

  • 如果它以/*==>开头删除所有行直到*/

2)另一种情况是处理

示例 - int studentId; //评论或/*评论*/

有人可以提供更好的方法吗?

java java-8

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

标签 统计

java ×2

java-8 ×1

spring ×1

spring-boot ×1

spring-retry ×1