springbootstarter开发
下面给一个例子
1、写一个自动配置类
package com.cache.service;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan(basePackages = {"com.cache.service"})
public class ServiceTestAutoConfigure {
@Bean("serviceTest")
@ConditionalOnMissingBean(ServiceTest.class)
public ServiceTest getService() {
return new ServiceTest();
}
}
2、配置resources/META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.topnet.cache.service.ServiceTestAutoConfigure
3、引入pom.xml
<dependency>
<groupId>com.topnet</groupId>
<artifactId>top-cache</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
4、自动注入
@Autowired
private ServiceTest serviceTest;
以上是 springbootstarter开发 的全部内容, 来源链接: utcz.com/z/516554.html