当前位置: 首页>>代码示例>>Scala>>正文


Scala Autowired类代码示例

本文整理汇总了Scala中org.springframework.beans.factory.annotation.Autowired的典型用法代码示例。如果您正苦于以下问题:Scala Autowired类的具体用法?Scala Autowired怎么用?Scala Autowired使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Autowired类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: ScalajHttpAdapter

//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery.utils

import org.springframework.beans.factory.annotation.{Autowired, Value}
import org.springframework.stereotype.Component

import scala.concurrent.{ExecutionContext, Future}
import scalaj.http.Http

@Component
class ScalajHttpAdapter @Autowired()(@Value("${http.timeouts:2000}") private val timeouts: Int) extends HttpAdapter {

  override def request(url: String, params: Map[String, String]): String =
    Http(url)
      .params(params)
      .timeout(timeouts, timeouts)
      .asString
      .body

  override def asyncRequest(url: String, params: Map[String, String])
                           (implicit executionContext: ExecutionContext): Future[String] =
    Future(request(url, params))
} 
开发者ID:piotrglazar,项目名称:receipt-lottery,代码行数:23,代码来源:ScalajHttpAdapter.scala

示例2: CustomerController

//设置package包名称以及导入依赖的类
package fr.sysf.sample.service


import java.net.HttpURLConnection
import javax.validation.Valid

import fr.sysf.sample.domain.Customer
import io.swagger.annotations.{Api, ApiOperation, ApiResponse, ApiResponses}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.{HttpStatus, MediaType, ResponseEntity}
import org.springframework.web.bind.annotation._


@Api(value = "Customers service", consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
@RestController
@RequestMapping(Array("/customers"))
class CustomerController {

  @Autowired
  private val customerRepository: CustomerRepository = null

  @ApiOperation(value = "Put_Customers", notes = "method to create new Customer or update customer")
  @ApiResponses(value = Array(
    new ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"),
    new ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"),
    new ApiResponse(code = HttpURLConnection.HTTP_ACCEPTED, response = classOf[Customer], message = "Success PUT")
  ))
  @RequestMapping(
    value = Array("/"),
    method = Array(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH),
    produces = Array(MediaType.APPLICATION_JSON_UTF8_VALUE))
  def setCustomer(
                   @Valid @RequestBody customer: Customer
                 ): ResponseEntity[Customer] = {

    val customerExisted = customerRepository.findByEmail(customer.email)
    if (customerExisted != null) {
      customer.id = customerExisted.id
      customer.version = customerExisted.version
    }
    val customerSaved = customerRepository.save(customer)

    new ResponseEntity[Customer](customerSaved, HttpStatus.ACCEPTED)
  }

} 
开发者ID:fpeyron,项目名称:sample-scala-mongo-rest,代码行数:47,代码来源:CustomerController.scala

示例3: es

//设置package包名称以及导入依赖的类
package fr.sysf.sample

import java.time.LocalDate

import fr.sysf.sample.domain.Customer
import fr.sysf.sample.service.CustomerRepository
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner


@RunWith(classOf[SpringJUnit4ClassRunner])
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = Array(classOf[ApplicationConfig]))
//@ContextConfiguration(classes = Array(classOf[ApplicationConfig]))
class CustomerDataTest {

  @Autowired
  private val customerRepository: CustomerRepository = null

  @Test
  def getHello {

    val customer = new Customer()
    customer.firstName = "Anna"
    customer.lastName = "Blum"
    customer.birthDate = LocalDate.of(1965, 2, 7)

    var request = customerRepository.save(customer)

    // getAll before insert
    assertThat(request).isNotNull
    assertThat(request.createdDate).isNotNull
    assertThat(request.updatedDate).isEqualTo(request.createdDate)
    Assertions.assertThat(request.version).isEqualTo(0l)

    request.city = "Paris"
    request = customerRepository.save(request)

    assertThat(request).isNotNull
    Assertions.assertThat(request.createdDate).isNotNull
    Assertions.assertThat(request.city).isEqualTo("Paris")
    Assertions.assertThat(request.version).isEqualTo(1l)


  }
} 
开发者ID:fpeyron,项目名称:sample-scala-mongo-rest,代码行数:52,代码来源:CustomerDataTest.scala

示例4: es

//设置package包名称以及导入依赖的类
package fr.sysf.sample

import org.junit.runner.RunWith
import org.junit.{Ignore, Test}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner


@RunWith(classOf[SpringJUnit4ClassRunner])
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = Array(classOf[ApplicationConfig]))
class ApiRestTest {

  @Autowired
  private val restTemplate: TestRestTemplate = null


  // todo: to complete
  @Ignore
  @Test
  def should_put_customer_when_it_does_not_exits {

  }
} 
开发者ID:fpeyron,项目名称:sample-scala-mongo-rest,代码行数:27,代码来源:ApiRestTest.scala

示例5: AppConfiguration

//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery.extension

import akka.actor.ActorSystem
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.{Bean, Configuration}

import scala.concurrent.ExecutionContext

@Configuration
class AppConfiguration {

  @Autowired
  var applicationContext: ApplicationContext = _

  @Bean
  def actorSystem(): ActorSystem = {
    val sys = ActorSystem()
    SpringExtension.provider.get(sys).initialize(applicationContext)
    sys
  }

  @Bean
  def executionContext(actorSystem: ActorSystem): ExecutionContext =
    actorSystem.dispatcher
} 
开发者ID:piotrglazar,项目名称:receipt-lottery,代码行数:27,代码来源:AppConfiguration.scala

示例6: ResultFetcher

//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery.core

import com.piotrglazar.receiptlottery.Token
import com.piotrglazar.receiptlottery.utils.HttpAdapter
import org.htmlcleaner.{HtmlCleaner, TagNode}
import org.springframework.beans.factory.annotation.{Autowired, Value}
import org.springframework.stereotype.Component

import scala.concurrent.{ExecutionContext, Future}

@Component
class ResultFetcher @Autowired()(@Value("${results.page}") private val pageAddress: String, private val httpAdapter: HttpAdapter,
                                 implicit private val executionContext: ExecutionContext) {

  def hasResult(token: Token): Future[Boolean] = {
    val rawContentFuture = httpAdapter.asyncRequest(pageAddress, Map("code" -> token.value))
    rawContentFuture.map { rawContent =>
      val cleanContent: TagNode = new HtmlCleaner().clean(rawContent)

      !getResultTables(cleanContent)
        .flatMap(getResultTableBody)
        .flatMap(getResultTableRows)
        .isEmpty
    }
  }

  private def getResultTables(page: TagNode): Array[TagNode] =
    page.getElementsByAttValue("class", "results-table", true, true)

  private def getResultTableBody(table: TagNode): Array[TagNode] =
    table.getElementsByName("tbody", true)

  private def getResultTableRows(tableBody: TagNode): Array[TagNode] =
    tableBody.getElementsByName("tr", true)
} 
开发者ID:piotrglazar,项目名称:receipt-lottery,代码行数:36,代码来源:ResultFetcher.scala

示例7: WorkingActor

//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery.core

import akka.actor.Actor
import com.piotrglazar.receiptlottery.{Token, VerifiedToken}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component

@Component("workingActor")
@Scope("prototype")
class WorkingActor @Autowired()(private val resultFetcher: ResultFetcher) extends Actor {

  implicit private val executionContext = context.system.dispatcher

  override def receive: Receive = {
    case token: Token =>
      val requester = sender()
      val resultFuture = resultFetcher.hasResult(token)
      resultFuture.onSuccess { case result => requester ! VerifiedToken(token, result) }
  }
} 
开发者ID:piotrglazar,项目名称:receipt-lottery,代码行数:22,代码来源:WorkingActor.scala

示例8: TokenReader

//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery.core

import com.piotrglazar.receiptlottery.Token
import org.springframework.beans.factory.annotation.{Value, Autowired}
import org.springframework.stereotype.Component
import rx.lang.scala.Observable

import scala.io.Source
import scala.util.{Failure, Success, Try}

@Component
class TokenReader @Autowired()(@Value("${token.file}") private val path: String) {

  def readTokens(): Observable[Token] = {
    readContent() match {
      case Success(items) => Observable.from(items)
      case Failure(e) => Observable.error(e)
    }
  }

  private def readContent(): Try[List[Token]] =
    Try {
      Source.fromInputStream(getClass.getResourceAsStream(path))
        .getLines()
        .filter(!_.isEmpty)
        .map(Token)
        .toList
    }
} 
开发者ID:piotrglazar,项目名称:receipt-lottery,代码行数:30,代码来源:TokenReader.scala

示例9: ReceiptLotteryTest

//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery

import akka.actor.ActorSystem
import org.springframework.beans.factory.annotation.{Qualifier, Autowired}
import org.springframework.test.context.ContextConfiguration

@ContextConfiguration(classes = Array[Class[_]](classOf[ReceiptLottery]))
class ReceiptLotteryTest extends BaseContextTest  {

  override def beforeAll(): Unit = {
    System.setProperty("token.file", "/testTokens.txt")
    System.setProperty("results.page", "https://loteriaparagonowa.gov.pl/wyniki")
    super.beforeAll()
  }

  @Autowired
  @Qualifier("actorSystem")
  var actorSystem: ActorSystem = _

  "ReceiptLottery" should "use actors to verify tokens" in {
    // given
    // context loaded

    // when
    new ReceiptLottery().runActors_=(actorSystem)

    // then
    System.setProperty("token.file", "")
  }
} 
开发者ID:piotrglazar,项目名称:receipt-lottery,代码行数:31,代码来源:ReceiptLotteryTest.scala

示例10: MyApp

//设置package包名称以及导入依赖的类
package com.kemalates.demo02

import com.kemalates.demo02.service.MyService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.{CommandLineRunner, SpringApplication}
import org.springframework.boot.autoconfigure.SpringBootApplication


@SpringBootApplication
class MyApp extends CommandLineRunner {

  @Autowired
  val myService: MyService = null

  override def run(args: String*) = {
    myService.sayHello()
  }
}

object MyApp extends App {
  SpringApplication run classOf[MyApp]
} 
开发者ID:kemalates,项目名称:scala-spring-boot-skeleton,代码行数:23,代码来源:MyApp.scala

示例11: ActuatorConfig

//设置package包名称以及导入依赖的类
package k8sslbnginxing.actuator
import akka.actor.ActorSystem
import com.google.common.base.Stopwatch
import io.fabric8.kubernetes.client.KubernetesClient
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.actuate.health.{Health, HealthIndicator}
import org.springframework.context.annotation.{Bean, Configuration}

@Configuration
class ActuatorConfig {

  @Autowired
  private var actorSystem: ActorSystem = _

  @Autowired
  private var kubernetesClient: KubernetesClient = _

  @Bean
  def kubernetesHealthIndicator: HealthIndicator = () => {
    try {
      val watch = Stopwatch.createStarted()
      kubernetesClient.services().inNamespace("default").withName("kubernetes").get()
      watch.stop()
      Health.up()
          .withDetail("get", "GET Service [email protected] in " + watch.toString)
          .build()
    } catch {
      case e: Exception =>
        Health.down(e).build()
    }
  }
} 
开发者ID:ferdinandhuebner,项目名称:k8s-slb-nginx-ing,代码行数:33,代码来源:ActuatorConfig.scala

示例12: ItalianInvoiceIDFinderTest

//设置package包名称以及导入依赖的类
package org.pdfextractor.algorithm.finder.it

import org.pdfextractor.algorithm.finder.AbstractFinderTest
import org.slf4j.{Logger, LoggerFactory}
import org.springframework.beans.factory.annotation.Autowired
import org.pdfextractor.algorithm.phrase.PhraseTypesStore

class ItalianInvoiceIDFinderTest extends AbstractFinderTest {

  val log: Logger = LoggerFactory.getLogger(classOf[PhraseTypesStore])

  @Autowired var italianInvoiceIDFinder: ItalianInvoiceIDFinder = _

  "Italian invoice ID finder" should "parse" in {
    val idText = "Numero fattura: 3816442625428252-20"
    val parsed = italianInvoiceIDFinder.parseValue(idText).asInstanceOf[String]
    assert("3816442625428252-20" == parsed)
  }

  "Italian invoice ID finder" should "find from start" in {
    assert(italianInvoiceIDFinder.searchPattern.get.findFirstIn("Fattura n.6 del 23.02.2016").nonEmpty)
  }

  "Italian invoice ID finder" should "find from line" in {
    assert(italianInvoiceIDFinder.getValuePattern.findFirstIn("Fattura n.6 del 23.02.2016").nonEmpty)
    assert("Fattura n.6" == italianInvoiceIDFinder.getValuePattern.findFirstIn("Fattura n.6 del 23.02.2016").get)
    assert("Fattura n.654343-3s" == italianInvoiceIDFinder.getValuePattern.findFirstIn("Fattura n.654343-3s del 23.02.2016").get)
    assert("654343-3s" == italianInvoiceIDFinder.StartR.replaceFirstIn("Fattura n.654343-3s", ""))
  }

} 
开发者ID:kveskimae,项目名称:pdfalg,代码行数:32,代码来源:ItalianInvoiceIDFinderTest.scala

示例13: EstonianInvoiceIDFinderTest

//设置package包名称以及导入依赖的类
package org.pdfextractor.algorithm.finder.et

import org.pdfextractor.algorithm.candidate.Candidate
import org.pdfextractor.algorithm.finder.{AbstractFinderTest, AbstractInvoiceFileReader}
import org.pdfextractor.algorithm.io._
import org.slf4j.{Logger, LoggerFactory}
import org.springframework.beans.factory.annotation.Autowired
import org.pdfextractor.algorithm.parser.{PDFFileParser, ParseResult, Phrase}
import org.pdfextractor.algorithm.phrase.PhraseTypesStore

import scala.collection.LinearSeq

class EstonianInvoiceIDFinderTest extends AbstractFinderTest {

  val log: Logger = LoggerFactory.getLogger(classOf[PhraseTypesStore])

  @Autowired var estonianInvoiceIDFinder: EstonianInvoiceIDFinder = _

  "Estonian invoice ID finder" should "find from phrase" in {
    val invoiceAsString = getStringFromFile("EestiEnergia.txt")
    val phrase: Phrase = new Phrase(1, 1, 1, 1, 1, invoiceAsString, false)
    val phrases: LinearSeq[Phrase] = LinearSeq(phrase)
    val parseResult: ParseResult = new ParseResult("", phrases)

    val candidates: Seq[Candidate] = estonianInvoiceIDFinder.findCandidates(parseResult)

    assert(candidates.nonEmpty)

    val foundValues: Seq[String] = candidates.map(_.getValue.asInstanceOf[String])

    assert(foundValues.head == "Arve nr 12345")
  }

  "Estonian invoice ID finder" should "find from real PDF" in {
    val inputStream = getInputStreamFromFile(AbstractInvoiceFileReader.Starman)
    val parseResult = PDFFileParser.parse(inputStream)
    val candidates = estonianInvoiceIDFinder.findCandidates(parseResult)

    assert(candidates.nonEmpty)
    assert(candidates.size == 1)

    val firstCandidate = candidates.head

    assert(Option(firstCandidate.value).isDefined)
    assert(Option(firstCandidate.x).isDefined)
    assert(Option(firstCandidate.y).isDefined)
    assert(firstCandidate.value == "Arve number A-123456")
    assert(330 == firstCandidate.x)
    assert(94 == firstCandidate.y)
  }

} 
开发者ID:kveskimae,项目名称:pdfalg,代码行数:53,代码来源:EstonianInvoiceIDFinderTest.scala

示例14: EstonianTotalFinderTest

//设置package包名称以及导入依赖的类
package org.pdfextractor.algorithm.finder.et

import org.pdfextractor.algorithm.candidate.{IsDouble, HasEuroSign}
import org.pdfextractor.algorithm.finder.{AbstractFinderTest, AbstractInvoiceFileReader}
import org.pdfextractor.algorithm.io._
import org.slf4j.{Logger, LoggerFactory}
import org.springframework.beans.factory.annotation.Autowired
import org.pdfextractor.algorithm.parser.PDFFileParser
import org.pdfextractor.algorithm.phrase.PhraseTypesStore
class EstonianTotalFinderTest extends AbstractFinderTest {

  val log: Logger = LoggerFactory.getLogger(classOf[PhraseTypesStore])

  @Autowired var estonianTotalFinder: EstonianTotalFinder = _

  "Estonian total finder" should "find from real invoice and have additional info present" in {
    val inputStream = getInputStreamFromFile(AbstractInvoiceFileReader.Starman)
    val parseResult = PDFFileParser.parse(inputStream)
    val candidates = estonianTotalFinder.findCandidates(parseResult)

    assert(candidates.nonEmpty)

    val firstCandidate = candidates.head

    assert(Option(firstCandidate.value).isDefined)
    assert(Option(firstCandidate.x).isDefined)
    assert(Option(firstCandidate.y).isDefined)
    assert(firstCandidate.value == 16.87d)
    assert(35 == firstCandidate.x)
    assert(414 == firstCandidate.y)
    assert(firstCandidate.properties.get(IsDouble).get.asInstanceOf[Boolean])
    assert(!firstCandidate.properties.get(HasEuroSign).get.asInstanceOf[Boolean])
  }

} 
开发者ID:kveskimae,项目名称:pdfalg,代码行数:36,代码来源:EstonianTotalFinderTest.scala

示例15: EstonianAccountNumberFinderTest

//设置package包名称以及导入依赖的类
package org.pdfextractor.algorithm.finder.et

import org.pdfextractor.algorithm.candidate.Candidate
import org.pdfextractor.algorithm.finder.{AbstractFinderTest, AbstractInvoiceFileReader}
import org.pdfextractor.algorithm.io._
import org.slf4j.{Logger, LoggerFactory}
import org.springframework.beans.factory.annotation.Autowired
import org.pdfextractor.algorithm.parser.{PDFFileParser, ParseResult}
import org.pdfextractor.algorithm.phrase.PhraseTypesStore

import scala.collection.LinearSeq

class EstonianAccountNumberFinderTest extends AbstractFinderTest {

  val log: Logger = LoggerFactory.getLogger(classOf[PhraseTypesStore])

  @Autowired var estonianAccountNumberFinder: EstonianAccountNumberFinder = _

  "Estonian account finder" should "find from real PDF" in {
    val inputStream = getInputStreamFromFile(AbstractInvoiceFileReader.Starman)
    val parseResult = PDFFileParser.parse(inputStream)
    val candidates = estonianAccountNumberFinder.findCandidates(parseResult)
    assert(candidates.nonEmpty)
    assert(4 == candidates.size)
    val foundValues: Seq[String] = candidates.map(_.getValue.asInstanceOf[String])
    assert(foundValues.contains("EE882200001180000796"))
    assert(foundValues.contains("EE921010002046022001"))
    assert(foundValues.contains("EE103300332097940003"))
    assert(foundValues.contains("EE561700017000030979"))
  }

  "Estonian account finder" should "find from invoice as a string" in {
    val invoiceAsString = getStringFromFile("EestiEnergia.txt")
    val candidates: Seq[Candidate] = estonianAccountNumberFinder.findCandidates(new ParseResult(invoiceAsString, LinearSeq.empty))
    val foundValues: Seq[String] = candidates.map(_.getValue.asInstanceOf[String])
    assert(foundValues.nonEmpty)
    assert(foundValues.contains("EE232200001180005555"))
    assert(foundValues.contains("EE081010002059413005"))
    assert(foundValues.contains("EE703300332099000006"))
    assert(foundValues.contains("EE431700017000115797"))
  }

  "Estonian account finder" should "discard invalid accounts" in {
    val invoiceAsString = getStringFromFile("RiggedInvoice.txt")
    val candidates: Seq[Candidate] = estonianAccountNumberFinder.findCandidates(new ParseResult(invoiceAsString, LinearSeq.empty))
    assert(candidates.isEmpty)
  }

} 
开发者ID:kveskimae,项目名称:pdfalg,代码行数:50,代码来源:EstonianAccountNumberFinderTest.scala


注:本文中的org.springframework.beans.factory.annotation.Autowired类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。