我在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源文件并删除它的所有注释.其余的造型应该保持不变.
我已经使用正则表达式完成了任务.
但我希望在不使用正则表达式的情况下完成同样的工作.
示例输入
// 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; //评论或/*评论*/
有人可以提供更好的方法吗?