Есть исключение: IllegalArgumentException Вопрос: в какие блоки мы попадаем и в каком порядке?
public class IllegalArgumentExceptionExt extends IllegalArgumentException {
public IllegalArgumentExceptionExt(String str) {
super(str);
}
}
public class TestException {
public static void main(String[] args) {
try {
if (true) {
throw new IllegalArgumentExceptionExt("demo exception");
}
} catch (NumberFormatException ex) {
System.out.println("1" + ex.getClass().getSimpleName());
throw ex;
} catch (IllegalArgumentExceptionExt ex) {
System.out.println("2" + ex.getClass().getSimpleName());
throw ex;
} catch (IllegalArgumentException ex) {
System.out.println("3" + ex.getClass().getSimpleName());
throw ex;
} catch (RuntimeException ex) {
System.out.println("4" + ex.getClass().getSimpleName());
throw ex;
} catch (Exception ex) {
System.out.println("5" + ex.getClass().getSimpleName());
throw ex;
} catch (Throwable ex) {
System.out.println("6" + ex.getClass().getSimpleName());
throw ex;
} finally {
System.out.println("finally");
}
System.out.println("end");
}
}
Имеем контроллер (можно и рест) вызываем метод doInTransaction Мы получим ожидаемое поведение?
org.springframework.transaction.annotation
@Controller
public class ServiceControllerDemo {
public String doInTransaction(RequestParams params){
....
return inTransaction(params);
}
@Transaction()
private String inTransaction(RequestParams params){
....
}
}
Имеем базовый абстрактный класс. Возможно ли функционал createNewPojo реализовать в абстрактном классе? И если да, то как..
public abstract class DemoAbstractClass {
abstract T createNewPojo();
}
Pojo Классы
@Data
public class DemoPojo1 {
private String name;
}
@Data
public class DemoPojo2 {
private String name;
}
Наследники:
public class ExtDemo extends DemoAbstractClass {
@Override
DemoPojo1 createNewPojo() {
return new DemoPojo1();
}
}
public class ExtDemo extends DemoAbstractClass {
@Override
DemoPojo2 createNewPojo() {
return new DemoPojo2();
}
}
Имеем: 1) интерфейс 2) 2 реализации 3) рест контроллер Этот проект соберется? Этот проект запустится?
public interface IBeanDemo {
public Long calculate(Long value);
}
@Component
public class Bean1 implements IBeanDemo{
@Override
public Long calculate(Long value) {
return 1L;
}
}
@Component()
public class Bean2 implements IBeanDemo{
@Override
public Long calculate(Long value) {
return 2L;
}
}
@RestController()
@RequestMapping("demorest1")
@RequiredArgsConstructor
public class DemoRestQ1 {
private final IBeanDemo bean;
@GetMapping("/calculate/{id}")
public Long runMethod(@PathVariable Long id){
return bean.calculate(id);
}
}
[[files/18deb3481dc06dde4b6fb4116468c849MD5.jpg|Open: photo171641.jpg]] ![[files/18deb3481dc06dde4b6fb4116468c849_MD5.jpg]]