67: Spring @Autowired

jk·2024년 4월 10일
0

kdt 풀스택

목록 보기
107/127



1.@Autowired 에 대하여 설명하시오.

  • Marks a constructor, field, setter method, or config method as to be autowired by Spring's dependency injection facilities.



2.아래에 대하여 설명하시오.(예습)

  • 생성자 주입: Marks the @Autowired on the constructor. It provides DI of a class through its constructor at the time of initializing the object.
  • Setter 주입: Marks the @Autowired on the setter method. It provides DI of a class through setter methods.
  • 필드 주입 : Marks the @Autowired on the field variables. It directly sets the DIs into the fields of a class.



3. 스프링부트에서 Datasource를 가져오기 위한 방법은?(해당 라이브러리 정리)

  • Datasource 관련 테스트 코드를 작성하시오.
	@Autowired
	private DataSource dataSource;
	@Test
	void testDataSource() {
		assertNotNull(dataSource);
	}
		<dependency>
			<groupId>oracle</groupId>
			<artifactId>ojdbc6</artifactId>
			<version>11.2.0.3</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ojdbc8</artifactId>
			<version>23.3.0.23.09</version>
		</dependency>
		<dependency>
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ojdbc11</artifactId>
			<version>23.3.0.23.09</version>
		</dependency>
		<dependency>
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ucp11</artifactId>
			<version>23.3.0.23.09</version>
		</dependency>
		<dependency>
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ucp</artifactId>
			<version>23.3.0.23.09</version>
		</dependency>
		<dependency>
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ojdbc10</artifactId>
			<version>19.22.0.0</version>
		</dependency>
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/xepdb1
#spring.datasource.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
#spring.datasource.url=jdbc:log4jdbc:oracle:thin:@localhost:1521/xepdb1
spring.datasource.username=scott
spring.datasource.password=tiger
profile
Brave but clumsy

0개의 댓글