관리 메뉴

LIFE & IT

STS 에서 동작하는 Spring 구조 테스트(1) 본문

웹 프로그래밍/Spring Framework

STS 에서 동작하는 Spring 구조 테스트(1)

프린이! 2020. 4. 15. 17:18

◎ JUNIT을 이용해 Controller 를 테스트 한 결과 Springfamework 가 STS 에서 어떻게 동작하는지 확인

 

정리가 미흡하거나 JUNIT 테스트 log 결과로 진행했기에 실제 Springframework 의 동작에 미흡한 부분이 있지만

구조를 어느정도 정리하고 넘어가기 위해 남김.

 

 

▷ 첨부파일 :

 

- java : BoardControllerTests.java , BoardController.java, BoardMapper.java, BoardMapper.xml, BoardService.java, BoardServiceImpl.java, Criteria.java, root-context.xml, servlet-context.xml

 

- txt : 원본 설명 파일 , 원본 log 파일

 

- pdf : spring 구조 이미지 파일

 

 

Spring_기본 동작순서_및_구조.pdf
0.08MB
BoardController.java
0.00MB
BoardControllerTests.java
0.01MB
BoardMapper.java
0.00MB
BoardMapper.xml
0.00MB
BoardService.java
0.00MB
BoardServiceImpl.java
0.00MB
Criteria.java
0.00MB
root-context.xml
0.00MB
servlet-context.xml
0.00MB
Spring 프로그램에서 springframework를 읽는 순서.txt
0.00MB

 

 

▷ 구조 이미지

이미지 출처: https://intro0517.tistory.com/151

 

▷ 설명

읽는 순서) 
 1,2.. 번호 순서대로 진행
 -: 하이픈 순서대로 진행

< 1 > web.xml 을 읽는다.
	1) root-context.xml 
		- <bean> 정의 읽음

	2) servlet-context.xml
		- <context:component-scan base-package="org.zerock.controller" /> 읽음
			- org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandler 요청해서 모두 읽음
		- <resources mapping="/resources/**" location="/resources/" /> 읽음
			- org.springframework.web.servlet.handler.SimpleUrlHandlerMapping 요청해서 읽음

		*결론) servlet-context.xml 의 내용을 거꾸로 읽어 올라갔다.

	3) 스프링 동작 시작 -> INFO : org.springframework.web.context.support.GenericWebApplicationContext - Refreshing org.springframework.web.context.support.GenericWebApplicationContext@1f28c152: startup date


< 2 > BoradControllerTests.java <실제 웹 동작 시작>

	
	1) @Before : 어노테이션을 읽었다.

	2) @Test 
		- public void testList() 실행한다.
			- 유저<client>가  /board/list 를 주소에 쳤다고 가정

	3) <Dispatcher> TestDispatcherServlet 호출( 유저<client>가 /board/list 를 클릭햇다고 가정됐기 때문에 )

	4) <Controller> org.zerock.controller.BoardController = "/board" 에 관련된 Controller 호출
		
		4-1) @GetMapping("/list") public void list(Criteria cri, Model model) 메소드 안에 내용을 순차적으로 실행하게 된다.
			
			 - model.addAttribute("list", service.getList(cri)); 메소드 실행.
				
				 - <Service> org.zerock.service.BoardServiceImpl = service.getList(cri) 호출이 실행된다.
				 *결론) 실제 BoardController 로직에서는 BoardService service 를 호출하게 작성되있지만, Spring 동작에서는 BoardService 클래스를 보이지 않게(log 에 보이지 않음) 먼저 호출하고 
                       			그 다음 BoardServiceImpl 클래스를 동작한다.(Impl 클래스는 log 에 보임)
					
					 - BoardMapper 클래스에 getList() 메소드를 호출.
						
						- mapper/BoardMapper.xml 호출 -> [SQL] 동작 실행 = INFO : jdbc.audit

	
		4-2) int total = service.getTotal(cri) 실행된다.
			
			 - <DAO> jdbc.audit = service.getTotal(cri) 호출
				
				- BoardServiceImpl 클래스에 getTotal 메소드의 return 값인 mapper.getTotalCount(cri) 에 의해 mapper 클래스의 DAO 동작을 하게 된다.
					
					- BoardMapper 클래스에 getTotalCount() 메소드를 호출.
						
						- mapper/BoardMapper.xml 호출 -> [SQL] 동작 실행 = INFO : jdbc.audit <<-- 로그에 찍힌 내용의 시작

	5) < 2 > 번 이후 모든 Spring 동작 완료 후 1번의 spring 완료 동작 -> INFO : org.springframework.web.context.support.GenericWebApplicationContext - Closing org.springframework.web.context.support.GenericWebApplicationContext

 

log 파일 : 위의 설명과 함께 찾기로 천천히 보면 읽어가는 구조를 알 수 있음

더보기

INFO : org.springframework.test.context.web.WebTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
INFO : org.springframework.test.context.web.WebTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4dfa3a9d, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@6eebc39e, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@464bee09, org.springframework.test.context.support.DirtiesContextTestExecutionListener@f6c48ac, org.springframework.test.context.transaction.TransactionalTestExecutionListener@13deb50e, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@239963d8]
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [file:src/main/webapp/WEB-INF/spring/root-context.xml]
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.web.context.support.GenericWebApplicationContext - Refreshing org.springframework.web.context.support.GenericWebApplicationContext@1f28c152: startup date [Tue Apr 14 16:15:40 KST 2020]; root of context hierarchy
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
INFO : jdbc.connection - 1. Connection opened
INFO : jdbc.audit - 1. Connection.new Connection returned 
INFO : com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Driver does not support get/set network timeout for connections. (net.sf.log4jdbc.sql.jdbcapi.ConnectionSpy.getNetworkTimeout()I)
INFO : jdbc.audit - 1. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 1. Connection.setAutoCommit(true) returned 
INFO : jdbc.audit - 1. Connection.isValid(1) returned true
INFO : jdbc.audit - 1. Connection.getTransactionIsolation() returned 2
INFO : com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
INFO : jdbc.connection - 2. Connection opened
INFO : jdbc.audit - 2. Connection.new Connection returned 
INFO : jdbc.audit - 2. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 2. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 3. Connection opened
INFO : jdbc.audit - 3. Connection.new Connection returned 
INFO : jdbc.audit - 3. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 3. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 4. Connection opened
INFO : jdbc.audit - 4. Connection.new Connection returned 
INFO : jdbc.audit - 4. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 4. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 5. Connection opened
INFO : jdbc.audit - 5. Connection.new Connection returned 
INFO : jdbc.audit - 5. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 5. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 6. Connection opened
INFO : jdbc.audit - 6. Connection.new Connection returned 
INFO : jdbc.audit - 6. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 6. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 7. Connection opened
INFO : jdbc.audit - 7. Connection.new Connection returned 
INFO : jdbc.audit - 7. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 7. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 8. Connection opened
INFO : jdbc.audit - 8. Connection.new Connection returned 
INFO : jdbc.audit - 8. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 8. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 9. Connection opened
INFO : jdbc.audit - 9. Connection.new Connection returned 
INFO : jdbc.audit - 9. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 9. Connection.setAutoCommit(true) returned 
INFO : jdbc.connection - 10. Connection opened
INFO : jdbc.audit - 10. Connection.new Connection returned 
INFO : jdbc.audit - 10. Connection.setReadOnly(false) returned 
INFO : jdbc.audit - 10. Connection.setAutoCommit(true) returned 
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/board/remove],methods=[POST]}" onto public java.lang.String org.zerock.controller.BoardController.remove(java.lang.Long,org.zerock.domain.Criteria,org.springframework.web.servlet.mvc.support.RedirectAttributes)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/board/get || /board/modify],methods=[GET]}" onto public void org.zerock.controller.BoardController.get(java.lang.Long,org.zerock.domain.Criteria,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/board/register],methods=[GET]}" onto public void org.zerock.controller.BoardController.register()
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/board/register],methods=[POST]}" onto public java.lang.String org.zerock.controller.BoardController.register(org.zerock.domain.BoardVO,org.springframework.web.servlet.mvc.support.RedirectAttributes)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/board/list],methods=[GET]}" onto public void org.zerock.controller.BoardController.list(org.zerock.domain.Criteria,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/board/modify],methods=[POST]}" onto public java.lang.String org.zerock.controller.BoardController.modify(org.zerock.domain.BoardVO,org.zerock.domain.Criteria,org.springframework.web.servlet.mvc.support.RedirectAttributes)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET]}" onto public java.lang.String org.zerock.controller.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.web.context.support.GenericWebApplicationContext@1f28c152: startup date [Tue Apr 14 16:15:40 KST 2020]; root of context hierarchy
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.web.context.support.GenericWebApplicationContext@1f28c152: startup date [Tue Apr 14 16:15:40 KST 2020]; root of context hierarchy
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.mock.web.MockServletContext - Initializing Spring FrameworkServlet ''
INFO : org.springframework.test.web.servlet.TestDispatcherServlet - FrameworkServlet '': initialization started
INFO : org.springframework.test.web.servlet.TestDispatcherServlet - FrameworkServlet '': initialization completed in 46 ms
INFO : org.zerock.controller.BoardController - +++++ paging List : Criteria(pageNum=1, amount=10, type=null, keyword=null)
INFO : org.zerock.service.BoardServiceImpl - >> BoardServiceImpl getList.... : Criteria(pageNum=1, amount=10, type=null, keyword=null)
INFO : jdbc.audit - 1. Connection.isValid(5) returned true
INFO : jdbc.audit - 1. Connection.getAutoCommit() returned true
INFO : jdbc.audit - 1. PreparedStatement.new PreparedStatement returned 
INFO : jdbc.audit - 1. Connection.prepareStatement(select
    bno, title, content, writer, regdate, updatedate
   from
      (
      select /*+INDEX_DESC(tbl_board pk_board) */
        rownum rn, bno, title, content, writer, regdate, updatedate
      from
       tbl_board
      where 
       
      
        
      
       
      rownum <= ?*?
      )
      where rn > (? -1)*?) returned net.sf.log4jdbc.sql.jdbcapi.PreparedStatementSpy@22175d4f
INFO : jdbc.audit - 1. PreparedStatement.setInt(1, 1) returned 
INFO : jdbc.audit - 1. PreparedStatement.setInt(2, 10) returned 
INFO : jdbc.audit - 1. PreparedStatement.setInt(3, 1) returned 
INFO : jdbc.audit - 1. PreparedStatement.setInt(4, 10) returned 
INFO : jdbc.sqlonly - select bno, title, content, writer, regdate, updatedate from ( select /*+INDEX_DESC(tbl_board 
pk_board) */ rownum rn, bno, title, content, writer, regdate, updatedate from tbl_board where 
rownum <= 1*10 ) where rn > (1 -1)*10 

INFO : jdbc.sqltiming - select bno, title, content, writer, regdate, updatedate from ( select /*+INDEX_DESC(tbl_board 
pk_board) */ rownum rn, bno, title, content, writer, regdate, updatedate from tbl_board where 
rownum <= 1*10 ) where rn > (1 -1)*10 
 {executed in 149 msec}
INFO : jdbc.audit - 1. PreparedStatement.execute() returned true
INFO : jdbc.resultset - 1. ResultSet.new ResultSet returned 
INFO : jdbc.audit - 1. PreparedStatement.getResultSet() returned net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy@408a247c
INFO : jdbc.resultset - 1. ResultSet.getMetaData() returned oracle.jdbc.driver.OracleResultSetMetaData@6b9c69a9
<생략>
INFO : jdbc.resultsettable -  <생략>

INFO : jdbc.resultset - 1. ResultSet.next() returned false
INFO : jdbc.resultset - 1. ResultSet.close() returned void
INFO : jdbc.audit - 1. Connection.getMetaData() returned oracle.jdbc.driver.OracleDatabaseMetaData@4c060c8f
INFO : jdbc.audit - 1. PreparedStatement.isClosed() returned false
INFO : jdbc.audit - 1. PreparedStatement.close() returned 
INFO : jdbc.audit - 1. Connection.clearWarnings() returned 
INFO : org.zerock.service.BoardServiceImpl - get total count
INFO : jdbc.audit - 1. Connection.getAutoCommit() returned true
INFO : jdbc.audit - 1. PreparedStatement.new PreparedStatement returned 
INFO : jdbc.audit - 1. Connection.prepareStatement(select count(*) from tbl_board where bno > 0) returned net.sf.log4jdbc.sql.jdbcapi.PreparedStatementSpy@4a1e3ac1
INFO : jdbc.sqlonly - select count(*) from tbl_board where bno > 0 

INFO : jdbc.sqltiming - select count(*) from tbl_board where bno > 0 
 {executed in 2 msec}
INFO : jdbc.audit - 1. PreparedStatement.execute() returned true
INFO : jdbc.resultset - 1. ResultSet.new ResultSet returned 
INFO : jdbc.audit - 1. PreparedStatement.getResultSet() returned net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy@6e78fcf5
INFO : jdbc.resultset - 1. ResultSet.getMetaData() returned oracle.jdbc.driver.OracleResultSetMetaData@56febdc
INFO : jdbc.resultset - 1. ResultSet.getType() returned 1003
INFO : jdbc.resultset - 1. ResultSet.next() returned true
INFO : jdbc.resultset - 1. ResultSet.getInt(COUNT(*)) returned 27
INFO : jdbc.resultset - 1. ResultSet.wasNull() returned false
INFO : jdbc.resultsettable - 
|---------|
|count(*) |
|---------|
|27       |
|---------|

INFO : jdbc.resultset - 1. ResultSet.next() returned false
INFO : jdbc.resultset - 1. ResultSet.close() returned void
INFO : jdbc.audit - 1. Connection.getMetaData() returned oracle.jdbc.driver.OracleDatabaseMetaData@4c060c8f
INFO : jdbc.audit - 1. PreparedStatement.isClosed() returned false
INFO : jdbc.audit - 1. PreparedStatement.close() returned 
INFO : jdbc.audit - 1. Connection.clearWarnings() returned 
INFO : org.zerock.controller.BoardController - total : 27
INFO : org.zerock.controller.BoardControllerTests - <생략>
INFO : org.springframework.web.context.support.GenericWebApplicationContext - Closing org.springframework.web.context.support.GenericWebApplicationContext@1f28c152: startup date [Tue Apr 14 16:15:40 KST 2020]; root of context hierarchy
INFO : com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
INFO : jdbc.connection - 1. Connection closed
INFO : jdbc.audit - 1. Connection.close() returned 
<생략>

INFO : jdbc.connection - 10. Connection closed
INFO : jdbc.audit - 10. Connection.close() returned 
INFO : com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.