标签:service 注解 form parse extern ram info pre except
1,@Scope 注解
@Scope默认是单例模式,即scope="singleton"。(全局有且仅有一个实例)
@Scope("prototype")多例 (每次获取Bean的时候会有一个新的实例)
import com.ccservice.flight.international.crawler.entity.CrawlerTask; import com.ccservice.flight.international.crawler.entity.HttpRequestInfo; import com.google.gson.JsonObject; @Component("AkWxpFetcher") @Scope("prototype") //多例 public class AkWxpFetcher extends BaseFetcher { }
2,@ActiveProfiles("test")
@ActiveProfiles
是Spring Boot的Test starter提供的注解,如果项目是像下面的方式依赖Test starter的话——
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
在测试类中引用
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import com.ccservice.flight.international.crawler.entity.CrawlerTask; import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; /** * @author WanFeng * @version 2019年7月23日下午3:16:31 */ @ActiveProfiles("test") @RunWith(SpringRunner.class) @SpringBootTest(classes = { AkWxpParser.class, Gson.class }) @Slf4j public class AkWxpParserTest { @Autowired @Qualifier("AkWxpParser") private IParser parser;//是接口 }
标签:service 注解 form parse extern ram info pre except
原文地址:https://www.cnblogs.com/wanfeng-huabi/p/11233628.html