码迷,mamicode.com
首页 > 其他好文 > 详细

Spingboot的部分注解以及作用

时间:2019-07-23 18:42:03      阅读:96      评论:0      收藏:0      [点我收藏+]

标签: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;//是接口 
}

 

 

Spingboot的部分注解以及作用

标签:service   注解   form   parse   extern   ram   info   pre   except   

原文地址:https://www.cnblogs.com/wanfeng-huabi/p/11233628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!