maven을 eclipse에서 maven project만들면서 pom.xml로만 써봤다.

CLI에서 메이븐을 사용해서 자바 소스를 집적 받아오고 또 메이븐 리파지터리에 저장할 수도 있다.

나도 아직 잘 모른다.

링크로 대체 - 이것저것 따라하다 보면 된다.

https://www.lesstif.com/display/JAVA/maven+deploy+plugin

기초적인 스프링 강의를 다 들었다면 누구나 설정할 수 있겠지만

차분히 하나씩 집어 보기로 한다.


JDBC : 자바와 데이터베이스를 연결시켜주는 기술

Java DataBase Connectivity

우리가 꼭알아야 할 것은 커넥션 풀을 만들어주는 DataSource
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.0.1.RELEASE</version>
</dependency>
를 받아서 보면 DataSource 관련 클래스가 있다. DriverManagerDataSource가 있다.
설정을 프로퍼티에 넣어서 빈 등록하면 된다.
apache commons에서 나온 SimpleDataSource나 BasicDataSource같은 것들도 있다.
여기서는 최근에 빠르다고 하는 hikari를 써보겠다. 
메이븐
<dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>2.7.2</version>
</dependency>
빈 등록
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="dataSourceClassName" value="com.mysql.jdbc.Driver" />
<property name="dataSourceProperties">
<props>
<prop key="url" >jdbc:mysql//localhost:3306/wook</prop>
<prop key="user">root</prop>
<prop key="password">root</prop>
</props>
</property>
</bean>

SqlSession : statement를 만들고 실행한다.

jsp부터 공부했다면 Statement와 execute() 메서드, ResultSet들을 알것이다.
이를 편리하게 쓰게 해주는 ibatis의 클래스다.
<bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory" >
<property name="dataSource" ref="dataSource" />
</bean>
openSession이란 메서드로 SqlSession을 가져온다.

이렇게 오픈하고 클로즈하는게 귀찮을 수 있다.
<bean class="org.mybatis.spring.SqlSessionTemplate" >
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
SqlSessinTemlate을 쓰면 오픈, 커밋, 클로즈의 귀찮음을 피할 수 있다.

이렇게만 설정하면 
org/apache/ibatis/transaction/TransactionFactory  가 없다고 에러가 발생한다.
많이 봤던 getConnection(), close(), commit(), rollback()같은 메서드가 있는 인터페이스다.

메이븐 등록을 해준다.
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.5</version>
</dependency>


다른 dataSource를 쓴다고 spring jdbc를 메이븐 주입안했다면 

org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy

를 찾는 에러가 발생한다. spring-jdbc도 필요하다.

트랜잭션 결과가 의도한 상태가 아닐 경우 

일일이 조건문을 만들어 에러코드를 설정하는 것은 번거롭고 중복 코드를 발생시키는 일이다.

간단히 입셉션으로 처리하고 입셉션을 따로 관리하는 클래스와 페이지를 만든다면 편리다.

스프링은 이를 위해 Interface HandlerExceptionResolver를 사용한다.

빈등록에는 많은 방법들이 있는데

@ControllerAdvice 애노테이션을 이용하는 방법이 있다.

@ControllerAdvice(value="test.mapping") public class ExceptionAdivisor { @ExceptionHandler(InsertException.class) public ModelAndView handleInsertException(InsertException e) { System.out.println("ControllerAdvice: "+e); ModelAndView mav = new ModelAndView("/common/insertError"); mav.addObject("exception", e); return mav; } }


사용 방법은 아주 간단하다.

@ControllerAdvice(value="적용 패키지") 를 적용한 클래스를 만들고

@ExceptionHandler(예외 클래스) 를 적용한 메서드를 만들면 된다.

파라메터로 입섹션을 받을 수 있고

return값은 뷰리졸버에 의해 처리 되기때문에 ModelAndView를 적용할 수 있다.

@ControllerAdvice가 아닌 @Controller 클래스에 @ExceptionHandler 메서드를 적용한다면

해당 클래스에서 발생하는 예외에 우선권을 가지고 처리한다.


하지만 스프링에서는 이것보다는 SimpleMappingExceptionResolver를 이용한 입셉션처리를 권장하고 있다.

SimpleMappingExceptionResolver를 상속받아  커스텀 클래스를 만들면

ajax와 페이지 이동 방식등을 구분해서 사용할 수 있는 등 좀 더 디테일하게 예외처리를 할 수 있다.

이부분은 아직 공부가 덜 되서 다음에 쓰도록 하겠습니다.


transact는 거래하다라는 뜻이다. 

transaction은 DB와의 거래가 완전히 이루어진후 commit하는 것을 말한다.

그렇지 않으면 rollback을 한다.


Mapper자동 설정을 했을 때

transaction을 어떻게 처리할 것인가 고민할 것입니다.


스프링에는 트랜잭션을 관리해주는 클래스가 있습니다.

이를 aop를 이용해서 활용하면 됩니다.



<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"> </property></bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes>      <tx:method name="*" rollback-for="Exception"></tx:method> </tx:attributes> </tx:advice> <bean id="myAdvice" class="test.mapping.Advisor"></bean> <aop:config> <aop:pointcut id="requiredTx" expression="execution(* test..*Impl.*(..))"> <aop:advisor advice-ref="txAdvice" pointcut-ref="requiredTx"></aop:advisor> </aop:pointcut></aop:config>


(코드 프리티파이 xml처리가 안되서 보기가 이상하나 양해바랍니다.)


누구나 한번 쯤 

sqlSessionFactory.openSession()

sqlSession.쿼리

sqlSession.close() 

이 중복코드가 귀찮다고 생각해봤을 것이다.


이를 위해서 MyBatis에서는 interface를 이용한 자동 매퍼 설정을 만들어났다.

@MapperScan이라는 애노테이션을 이용하면 된다.


1. 일단 @Configuration 클래스를 만든다.

@Configuration @MapperScan(basePackages="test.mapping", annotationClass=Mapper.class) public class MapperConfigurer { }

2. 매퍼 인터페이스를 만든다.

@Mapper public interface DynamicMapper { @Select("select * from lcate where seq = #{num }") public List<Map> selectList(Map num);

@Insert("insert into lcate(code, name) values('003', '김성욱')") public int insertListMember(); }

편의상 xml 파일을 만들지 않고 애노테이션을 사용해서 쿼리문을 만들었다.

3. @Autowired로 다음과 같이 Injection을 한다.

@Autowired
DynamicMapper dynamicMapper;

4. 메서드를 호출한다

dynamicMapper.insertListMeber(); 와 같이 호출하면 된다.


XML설정

advice 클래스

public class Advisor {

public String returner(ProceedingJoinPoint joinPoint, HttpServletRequest req) throws Throwable  {

String URI = req.getRequestURI();

String contextPath = req.getContextPath();

joinPoint.proceed();

System.out.println("after");

System.out.println(URI);

System.out.println(contextPath);

String returnURI = URI.substring(contextPath.length()); 

return returnURI;

}

}

advice를 등록한다.

<bean id="myAdvice" class="com.zxy.Advisor" >

AOP-Config설정을 한다

<aop:config>

<aop:aspect ref="myAdvice">

<aop:pointcut id="myPointCut" expression="execution(* test..*Controller.*(..)) and args(req)" />

<aop:around method="returner" pointcut-ref="myPointCut" />

</aop:aspect>

<aop:aspect ref="myAdvice">

<aop:pointcut id="myPointCut2" 

expression="execution(* test..*(javax.servlet.http.HttpServletRequest, String)) and args(req, ctg)" />

<aop:around method="returner3" pointcut-ref="myPointCut2" />

</aop:aspect>

</aop:config>

<aop:aspect>태그의 ref는 참조할 advice bean id

<aop:pointcut> aspect적용 지점
     expression : 적용할 메서드 경로
execution은 메서드 전체 형식으로 지정한다.
접근제한자 반환타입 패키지를 포함한 메서드명 (인자)
<aop:around> method는 aspect로 동작할 메서드
   pointcut-ref는 참조할 pointcut id


HttpServletRequest를 받아서 URI를 받아 쓰고 싶은 경우가 생길 것이다.

파라메터를 받아 쓰고 싶은 경우는

execution에서 지정한 메서드 인자를 (..) 대신 타입을 패키지를 포함해서 써주고 args()도 추가해 주어야 한다.

(javax.servlet.http.HttpServletRequest, String) and args(req, ctg)

args()의 인자는 변수명을 쓴다.


전통적인 폭포수 개발방법 부터  최근의 애자일 방법론 등 소프트웨어 공학으로 이미 정립된 방법론이 많이 있지만

이미 있을지도 모르지만 나만의 개발 방법론을 정립해야겠다.


viewController


필요한 정보를 뿌려줄 경로 매핑


필요한 정보

title : 페이지 이름
model : 혹은 맵, 요청 정보가 담긴 객체로 주로 맵을 사용
     페이징 처리를 한다면 페이징 객체도 담음

메서드 이름을 어떻게 정해서 구분할 것인가?
DB하나의 튜플만 보여주는 경우와 list를 보여주는 경우
하나의 투플만 보여줄 경우 - 페이징 처리가 필요 없다.
메서드를 구분할 것인가 컨트롤러를 나눌 것인가?
예) 회원 목록을과 회원 정보, member 테이블에 member객체들
selectMember, selectMemberOne, selectOneMember
selectMemberList, selectListMember
아무래도 메서드 구분을 쉽게 하려면 one이나 list를 select다음에 붙이는게 좋지만
회화적으로는 뭔가 어색
정규식 표현
select*List, select*One, selectList*,selectOne*



항상 예상대로 개발 속도가 나질 않는다.

도와주는 사람은 아무도 없고 기간 압박은 커지고 스트레스만 쌓인다


09월21일 공부

redirect에 modelAttribute를 넘겨 주려면?


Model대신에 RedirectAttributes나 RedirectAttributesModelMap을 쓴다.

메소드는 addFlashAttribute를 사용해야 수신 컨트롤러 ModelAttribute와 충돌이 일어나지 않는다.


spring:message에는 다음 7가지가 있습니다.

code:         fmt:message의 key에 해당

arguments:                리소스 번들의 메시지에 {0}, {1} 같은 기호 자리에 들어갈 값을 나열

argumentSeparator:    arguments 속성에 값을 구분하는 기호, 기본은 콤마(',') 

text:                          code에 해당하는 메시지가 리소스 번들에 없을 때 사용될 메시지

message:                  MessageSourceResolvable 인터페이스를 구현한 객체 또는 MessageSourceResolvable를 나타내는 spel 식. 에러 메시지를 표시하려고 한다면 필요하겠죠.

htmlEscape:              true일 때 HTML 엔티티를 인코딩

javaScriptEscape:      true일 때 자바스크립트 문자열로 인코딩 

var:                           fmt:message와 동일

scope:                      fmt:message와 동일



'학습일기' 카테고리의 다른 글

네비게이션 관리를 효율적으로 하고 싶다.  (0) 2017.11.10
09월15일 학습일기  (0) 2017.09.15
08월21일 학습일기  (0) 2017.08.21
08월07일 학습일기  (0) 2017.08.07
08월02일 학습일기  (0) 2017.08.03

Software Process Improvement and Capability dEtermination

0~6 까지


2차원 표현



프로세스를 수행한 후 자세한 측정값을 수집하고 분석하는 단계는?

4 Predictable



보통 cmm 단계가 많다. 내가 일하는 환경도 그렇다 아니 그보다 좋지도 않다. 영웅적 개인도 없다.


최소한 2단계가 될 수 있도록 노력은 해야 할 것 같지만 작은 회사에서는 이런 것도 힘들다.



소프트웨어 프로세스가 문서화 되어 규격화 되어있는 단계는 ?


CMM3 Defined



SEPG (Software Engineer Process Group)



개발 공정, 비용, 일정, 기능이 통제되고 있고 소프트웨어 품질에 대하여 추적이 가능한 단계는?




'소프트웨어 공학' 카테고리의 다른 글

소프트웨어 프로덕트 라인  (0) 2017.07.15

+ Recent posts