Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Service
- public class ItemService {
- private List<String> list = Arrays.asList("A", "B", "C", "D", "E");
- @Autowired
- private ItemRepository itemRepository;
- @Transactional
- @Scheduled(fixedDelay = 1000 * 10)
- public void doSomething() {
- System.out.println("Run!");
- for (int i = 0; i < 5; i++) {
- doOneThing(new Item(i, list.get(i)));
- }
- }
- private void doOneThing(Item item) {
- System.out.println("Insert: " + item);
- if ("D".equals(item.getName())) {
- throw new RuntimeException("Hello");
- }
- itemRepository.save(item);
- }
- }
- public interface ItemRepository extends JpaRepository<Item, Integer>{
- }
- @Entity
- public class Item {
- @Id
- @GeneratedValue
- private int id;
- private String name;
- public Item() {
- }
- public Item(int id, String name) {
- this.id = id;
- this.name = name;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Override
- public String toString() {
- return "Item{" +
- "id=" + id +
- ", name='" + name + '\'' +
- '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement