BXCM 표준
1. Controller, Service, Component , DBIO 사용 공통
1.1. 필수 작성 사항
Controller, Service, Component , DBIO 사용 시 공통적인 필수 작성 사항에 대해 설명한다.
(1) @BxmCategory
Controller, Service, Component 의 클래스와 각 클래스의 메소드는 @BxmCategory 어노테이션을 포함 해야 한다(DBIO는 소스생성 방식이므로 개발자가 직접 작성하지 않음).
-
Class에 정의된 @BxmCategory 어노테이션
@Service
@BxmCategory(logicalName="직원조회 서비스", description="직원조회를 위한 서비스이다.")
public class EmployeeService {
private Logger logger= LoggerFactory.getLogger(getClass());
... ...
}
-
메소드에 정의된 @BxmCategory 어노테이션
@BxmCategory(logicalName = "직원정보 단건 조회")
public EmpIO retrieveEmp(EmpIO input)
{
logger.debug("============== SERVICE START ==============");
logger.debug("input = {}", input);
... ...
}
(2) Application Exception
Service와 Component 등 업무 소스에서는 예외처리를 하지 않는 것이 원칙이나, 예외처리시에는 반드시 bxmc.core.ext.exception.DefaultApplicationException를 throws 해야 한다.
@BxmCategory(logicalName = "직원정보 단건 조회")
public EmpIO retrieveEmp(EmpIO input) {
logger.debug("============== SERVICE START ==============");
logger.debug("input = {}", input);
... ...
try {
/* 업무 처리 */
} catch (DefaultApplicationException e) {
// 메시지 내용
throw new DefaultApplicationException("bxmc.test...", null, e);
}
}
1.2. 금지 항목
Service, Component, DBIO 사용 시 사용하지 말아야 하는 항목에 대해 설명한다.
(1) 객체 직접 생성 금지
Service, Component, DBIO는 프레임워크에서 관리하는 객체이므로 개발자가 new를 통해 직접 객체를 생성하지 않는다.
/* 직접 New 연산자를 통해서 생성하면 안된다 */
private EmployeeDbio employeeDbio = new EmployeeDbio();
업무 클래스의 객체의 생성은 직접 생성하지 않고 멤버변수 선언부에 getBean을 사용하거나, @Autowired Annotation을 사용하여 가져온다.
-
getBean 사용
employeeDbio = DefaultApplicationContext.getBean(employeeDbio, EmployeeDbio.class);
-
Autowired Annotation 사용
/* @Autowired Annotation 생성 */
@Autowired
private EmployeeDbio employeeDbio;
모놀로식 어플리케이션과 같은 구조라면 getBean() 방식, 마이크로서비스 구조라면 @Autowired Annotation 방식을 권장한다. |
(2) 데이터 객체를 멤버변수로 포함 금지
Service, Component, DBIO는 싱글톤 객체로 해당 클래스의 인스턴스는 프래임워크 내에 1개만 생성 된다. 따라서, 데이터를 저장하는 일반객체(원시타입 포함) 및 IO 객체를 멤버 변수로 가지고 있게 되면 객체의 데이터가 공유되는 형태가 되므로 사용하지 않아야 한다(버그발생가능)
(3) 자신의 타입을 멤버 변수에 포함 금지
Service, Component 등의 Bean 클래스의 경우 자신을 멤버 변수로 갖는 구조는 허용되지 않는다.
@BxmCategory(logicalName="샘플 Component", description="")
public class EmployeeComponent {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
/* EmployeeComponent Bean이 자기 자신(EmployeeComponent)을 맴버변수로 가지고 있으면 안된다 */
private EmployeeComponent employeeComponent;
@BxmCategory(logicalName="사원 조회", description="")
public EmployeeIO getEmployee(int empNo){
... ...
}
(4) 멤버변수의 get/set 메소드 작성 금지
@Service
@BxmCategory(logicalName="직원조회 서비스", description="직원조회를 위한 서비스이다.")
public class EmployeeService {
private Logger logger= LoggerFactory.getLogger(getClass());
@Autowired
private EmployeeComponent employeeComponent;
/* 멤버변수의 get 메소드가 있으면 안된다 */
public EmployeeComponent getEmployeeComponent() {
return employeeComponent;
}
/* 멤버변수의 set 메소드가 있으면 안된다 */
public void setEmployeeComponent(EmployeeComponent employeeComponent) {
this.employeeComponent = employeeComponent;
}
... ...
}
2. Controller
4. Component
4.1. 필수 작성 사항
Component 작성 시 필수로 작성해야 하는 항목에 대해 설명한다.
(1) @Component
Component는 @Component 어노테이션을 클래스 정의부에 포함한다.
/* Component 작성 시 필수 어노테이션 */
@Component
@BxmCategory(logicalName = "샘플직원정보관리")
public class EmpComponent {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
... ...
}
배치 Component(ItemReader, ItemProcessor, ItemWriter, Tasklet Interface로 구현)일 경우에는 Component 명을 명시한다.
/* Component 작성 시 필수 어노테이션 */
@Scope("step")
@Component("SampleComponent")
public class SampleComponent implements ItemProcessor<Sampleinputdto, Sampleoutputdto>, ItemStream, ItemReader<Sampleinputdto>, ItemWriter<Sampleoutputdto>
{
final Logger logger = LoggerFactory.getLogger(this.getClass());
private Demployee001 demployee001;
... ...
}
4.2. 금지 항목
Component 작성시 금지 항목에 대해 설명한다.
(1) Controller, Service 직접 호출 금지
Component 에서 Service를 호출 할 수 없다.
@Component
@BxmCategory(logicalName = "샘플직원정보관리")
public class EmpComponent {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
/* Service */
@Autowired
private EmployeeService employeeService; // 금지
@BxmCategory(logicalName = "단건 조회")
public EmpOut getEmpInf(EmpIn input) throws tApplicationException {
/* Component에서 Service를 호출하면 안된다 */
employeeService.getmSmpEmpInfMng();
return new EmpOut();
}
}
5. DBIO
5.1. 금지 항목
다음은 DBIO를 사용시 주의 사항에 대한 설명이다.
(1) DBIO 인터페이스 구현 금지
프래임워크에서 DI(Dependency Injection)을 통해 구현클래스를 주입하므로 DBIO 인터페이스를 구현하는 구현클래스를 개발자가 직접 작성하지 않는다.
(2) 인터페이스 파일 직접 편집 금지
DBIO는 .dbio 파일과 .java(interface로 정의됨)이 한 쌍으로 생성되며 .java 파일은 개발자가 직접 작성/편집하지 않는다.
(3) DBIO 에 생성하는 SQL 의 개수는 10개 미만으로 권장한다.
SQL의 개수가 너무 많으면 DBIO 에디터 동작 및 커밋 동작이 느려질 수 있다.
7. @BxmCategory
8. 어노테이션 요약
어노테이션은 JAVA 메타 언어로 소스 상에 표기하는 것만으로 런타임에 어떤 기능을 수행하거나, 클래스로부터 어떤 정보를 추출 할 수 있도록 한다.
구분 | 설명 | 표기위치 |
---|---|---|
@RestController |
Controller클래스로 기능함 |
Controller 클래스 선언부 |
@RequestMapping |
Controller의 URL 경로 매핑 정보 |
Controller 클래스 / public 메소드 선언부 |
@GetMapping |
HTTP GET 요청 매핑 정보 |
Controller public 메소드 선언부 |
@PostMapping |
HTTP GET 요청 매핑 정보 |
Controller public 메소드 선언부 |
@Service |
Service 클래스로 기능함 |
Service 클래스 선언부 |
@Component |
Component 클래스로 기능함 |
Component 클래스 선언부 |
@BxmDataAccess |
DBIO로 기능함 |
DBIO 인터페이스 선언부 (자동 생성) |
@BxmCategory |
논리명 입력 |
Controller 클래스 선언부 Controller 클래스 public 메소드 선언부 Service 클래스 선언부 Service 클래스 public 메소드 선언부 Component 클래스 선언부 Component 클래스 public 메소드 선언부 DBIO 인터페이스 선언부 (자동 생성) DBIO 인터페이스 메소드 선언부 (자동 생성) |
@Autowired |
Bean 자동 주입. |
Controller, Service, Component 의 멤버변수 선언 위치 |
@Transactional |
Transaction을 처리할 때 사용 (Transaction 분리 시 사용) |
Transaction을 처리할 메소드 선언부 |