Content |
naver 메일
아이디 aicore11
비밀번호 java0313!
깃허브의 코드와 지금 환경의 코드와 다른 점
1. 외부 네트워크 연결
설정파일의 https 프로토콜이 동작 안함
https -> http로 변경해야 함
src/main/webapp/WEB-INF/spring 폴더의
root-context.ml
appServlet/servlet-context.xml
라이브러리 파일이 내려받아지지 않음(pom.xml에 설정한)
미리 내려받아진 repository를 이용
네이버 메일에서 m2.zip파일을 내려받아서
.m2/repository 폴더를 덮어쓰세요.
settings.xml 파일은 제외
2. 일부 파일의 경로
c:/dev/ -> 실제 dev가 있는 경로로 수정
root-context.xml파일에서 데이터베이스 파일의 경로 수정
--------------------------
1, 2일차 정리
5일간 교육 내용
1. DI
2. Spring Web MVC
3. Servlet/JSP
4. JDBC
정규 교육과정
- 자바프로그래밍 -> 자바 프로그래밍 워크샵(JDBC) -> Servlet/JSP
-> RMI -> EJB -> OOAD(분석 설계)
* HTML/CSS/JavaScript
지금 교육은
- 자바프로그래밍(JDBC) -> 스프링(View를 표현하기 위한 기술: JSP, Thymeleaf)
1. DI
EMPLOYEES 테이블 데이터를 CRUD(관리)하는 애플리케이션을 자바로
DB와 연동하는 클래스 : DAO, Repository 클래스 - EmpRepository, IEmpRepository
biz로직을 구현한 클래스 : Service 클래스 - EmpService, IEmpService
관계의 복잡성을 줄이기 위해, 서비스 클래스에서 트랜잭션 처리
요청을 처리하는 클래스 : Controller 클랫 - EmpController
흐름은 : 컨트롤러 -> 서비스 -> 리포지토리 -> JDBCTemplate -> DataSource
의존성 주입은 미리 만들어진 객체를 전달해서 사용하게 함
객체를 생성하는 것 : 빈 생성,
annotation으로 하려면
@Component, @Service, @Repository
@Controller
객체를 전달하는 것 : 의존성 주입, 생성자 +
setter + 서비스 -> 리포지토리 -> 데이터베이스
*예외발생하면?
*자바의 재정의 규칙 중 예외관련 규칙
부모에서 throws 하지 않은 새로운 예외는 자식의
메서드에서 throws 할 수 없다.
public interface IEmpRepository {
int getEmpCount(); //throws SQLException;
}
public class EmpRepository
implements IEmpRepository {
public int getEmpCount() { // throws SQLException {
try {
//sql 예외가 발생하는 문장
}catch(SQLException e) {
throw new RuntimeException(e);
}
return 0;
}
}
--------------------------------
Spring Web MVC 예제를 실행시키려면...
WebMVC프로젝트를 실행시키려면
1. 데이터베이스 설치 및 설정
오라클 데이터베이스(설치되어 있음)
oracle express edition 11g r2의 hr 계정을 활성화 해야 함
시작 -> oracle -> SQL 명령줄 실행(SQL Command Line)
conn /as sysdba <- 데이터베이스에 관리자 권한 접속
alter user hr account unlock identified by hr;
계정 비번
conn hr/hr <-- hr 계정으로 접속
select count(*) from empoyees; <-- sql 구문 테스트 결과는 107여야 함
2. 스프링 설정파일(root-context.xml, servlet-context.xml)파일의 https를 http로 변경
3. servlet-context.xml 파일에 뷰컨트롤러 추가
home.jsp 파일은 http://localhost/myapp/을 실행시켰을 때 보일 화면
4. Run -> Run AS -> Run on Server
--------------------------
web.xml 설명
web.xml 파일의 DispatcherServlet은 init(ServletConfig) 메서드를 통해
서블릿을 초기화 하는데, init() 메서드가 실행될 때 서블릿 초기화 파라미터를
읽어 빈을 컨텍스트에 로드합니다.
서블릿의 초기화 파라미터는 ServletConfig 클래스의 getInitParameter()를
이용해서 읽을 수 있습니다.
web.xml 파일의 ContextLoaderListener 리스너는 ServletContextListener 인터페이스를
구현한 클래스 입니다. 이 클래스의 contextInitialized(ServletContextEvent)메서드를
재정의해 놓고 있으며 ServletContextEvent객체에서 ServletContext 객체를 얻고
ServletContext 객체의 getInitParameter() 메서드를 이용해서 컨텍스트 초기화
파라미터를 읽을 수 있습니다. contextInitialized() 메서드는 컨텍스트가 초기화될 때
호출됩니다.
|