데이터베이스 호출을 작성하기 위해 jdbcTemplate을 사용하고 있지만 autowired했지만 jdbcTemplate 인스턴스가 없습니다. 봄 applicationContext.xml에서 스프링 주석을 사용하여 jdbcTemplate의 인스턴스를 가져 오지 못했습니다.
package com.mypackage.dao
@Repository
public class CustomerDaoImpl implements CustomerDao {
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public Customer findCustomer(){
...........
jdbcTemplate.execute ......
...........
}
}
는
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="initialSize" value="1" />
<property name="maxActive" value="3" />
</bean>
<context:component-scan base-package="com.mypackage">
<context:exclude-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
database.properties 어떤 영역에서 내가 실수를 만들고있어
database.url=jdbc:oracle:thin:@myhost:1521:OQA1
database.username=my_app
database.password=my_app_password
database.driverClassName=oracle.jdbc.OracleDriver
파일?
---------------- 편집 : 상위 계층을 추가 ----------------
package com.mypackage.rest
@Service("customerResource")
@Path("/customer")
public class CustomerResource extends AbstractResource{
@Autowired
private CustomerDao customerDao;
}
이것은 괜찮습니다. 예외는 무엇입니까? database.properties 파일이 Spring에 의해로드되어 있습니까? 당신은 tx : annotation-driven? –
응용 프로그램 예외가 표시됩니까? –
@FredClose 닫기 jpaTemplate 인스턴스가 초기화되지 않아 NullPointer를 제외한 모든 예외가 표시되지 않습니다. 나는 tx를 가능하게하지 않았다 : 주석 중심 적으로,이 문제가 발생할 것인가? – Pankaj