springboot + nutz dao + druid 配置代码
pom.xml:添加druid 与 nutz 相关依赖 ,能自动整合spring boot
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz-plugins-spring-boot-starter</artifactId>
<version>1.r.68.v20191031</version>
</dependency>
添加一个Bean,用于IoC
@Configuration public class DaoConfiguration { @Bean @Primary public Dao getDao(DataSource dataSource) { // 创建一个NutDao实例,在真实项目中, NutDao通常由ioc托管, 使用注入的方式获得. Dao dao = new NutDao(dataSource); return dao; } }
然后在Service就可以调用了
@RestController public class DemoController { @Autowired private Dao dao; @ApiOperation(value = "count") @GetMapping("/count") public void test() { System.out.println(dao.count("deliver_bill_info") + " 条"); }