使用spring-boot 2.7.2错误- *java.lang.空指针异常:无法调用“组织.Spring框架.jdbc.核心.jdbcTemplate.查询(字符串,组织.Spring框架.jdbc.核心.行Map器)”,因为“此.jdbcTemplate”为空 *
@Service
public class UserServiceImpl implements UserService {
.....
@Autowired
private UserDao userDao;
}
@Component
public class UserDaoImpl implements UserDao {
private JdbcTemplate jdbcTemplate;
@Autowired
public UserDaoImpl(JdbcTemplate jdbcTemplatn) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public List<AttributeData> getAttributes() {
String query = "select attributeid, ....";
List<AttributeData> attributes = jdbcTemplate.query(query, new AttributeMapper());
return attributes;
}
}
application.properties :
# Oracle db related
spring.datasource.url=jdbc:oracle:thin:@localhost....
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
# JPA related
oracle.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
1条答案
按热度按时间uujelgoq1#
只是意味着您没有定义JdbcTemplate的
@Bean
,例如