我正在开发一个SpringBoot应用程序(例如MyApp),它依赖于两个具有不同实现的数据项目:
数据了jdbc.jar
spring-boot-starter-jdbcmy来构建公开我的应用程序将使用的JDBCDataService类示例代码:
@Service
public class JDBCDataServiceImpl implements JDBCDataService {
@Autowired
private JDBCDataRepository jdbcDataRepository;
...
}
Run Code Online (Sandbox Code Playgroud)
my.data.jdbcJDBCTemplate样本库:
@Repository
public class JDBCDataRepositoryImpl implements JDBCDataRepository {
@Autowired
protected JdbcTemplate jdbcTemplate;
...
}
Run Code Online (Sandbox Code Playgroud)
数据jpa.jar
spring-boot-starter-data-jpa也暴露了我的应用程序也将使用的JPADataService类示例代码:
@Service
public class JPADataServiceImpl implements JPADataService {
@Autowired
private JPADataRepository jpaDataRepository;
...
}
Run Code Online (Sandbox Code Playgroud)
my.data.jpaCrudRepository接口样本库:
@Repository
public interface JPADataRepository extends CrudRepository<MyObject, Integer{
...
}
Run Code Online (Sandbox Code Playgroud)
在我的SpringBoot项目中,我有以下SpringBoot主应用程序:
@SpringBootApplication
public class MyApp extends SpringBootServletInitializer { …Run Code Online (Sandbox Code Playgroud)