本文整理汇总了Scala中org.springframework.boot.autoconfigure.SpringBootApplication类的典型用法代码示例。如果您正苦于以下问题:Scala SpringBootApplication类的具体用法?Scala SpringBootApplication怎么用?Scala SpringBootApplication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpringBootApplication类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Application
//设置package包名称以及导入依赖的类
package pl.mojepanstwo.sap.toakoma
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.batch.core.launch.JobLauncher
import org.springframework.batch.core.Job
import org.springframework.batch.core.JobParametersBuilder
import pl.mojepanstwo.sap.toakoma.jobs.Isap2AkomaJob
@SpringBootApplication
class Application
object Main {
def main(args: Array[String]): Unit = {
if(!Cli.parseArgs(args)) {
Cli.printHelp
return
}
try {
val ctx = SpringApplication.run(classOf[Application])
val jobLauncher = ctx.getBean(classOf[JobLauncher])
if(Cli.JOB.ISAP_2_AKOMA.toString == Cli.args.getOptionValue(Cli.OPT.command.toString)) {
val pdf2XmlJob = ctx.getBean(Isap2AkomaJob.NAME, classOf[Job])
val jobParameters = new JobParametersBuilder().addString(Cli.OPT.id.toString,
Cli.args.getOptionValue(Cli.OPT.id.toString))
.toJobParameters()
val jobExecution = jobLauncher.run(pdf2XmlJob, jobParameters)
}
// if(Cli.JOB.XML_2_DB.toString == Cli.args.getOptionValue(Cli.OPT.command.toString)) {
// val pdf2XmlJob = ctx.getBean(Xml2DbJob.NAME, classOf[Job])
// val jobParameters = new JobParametersBuilder().toJobParameters()
// val jobExecution = jobLauncher.run(pdf2XmlJob, jobParameters)
// }
} catch {
case e:
Throwable => e.printStackTrace()
System.exit(0)
}
}
}
开发者ID:PrawoPolskie,项目名称:toakoma,代码行数:44,代码来源:Main.scala
示例2: 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
示例3: WebServicesApplication
//设置package包名称以及导入依赖的类
package com.github.swwjf
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.builder.SpringApplicationBuilder
import org.springframework.boot.context.web.SpringBootServletInitializer
import org.springframework.context.annotation.ComponentScan
@SpringBootApplication
@ComponentScan(Array("com.github.swwjf"))
class WebServicesApplication extends SpringBootServletInitializer {
override def configure(builder: SpringApplicationBuilder): SpringApplicationBuilder =
builder.sources(classOf[WebServicesApplication])
}
object WebServicesApplication {
def main(args: Array[String]) {
new SpringApplicationBuilder(classOf[WebServicesApplication]).run(args: _*)
}
}
开发者ID:andrei-l,项目名称:scala-webapp-with-java-frameworks,代码行数:20,代码来源:WebServicesApplication.scala
示例4: ExampleStream
//设置package包名称以及导入依赖的类
package com.getindata.examples
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.cloud.stream.annotation.{EnableBinding, Input, Output, StreamListener}
import org.springframework.cloud.stream.messaging.{Processor, Sink, Source}
import reactor.core.publisher.Flux
import scala.compat.java8.FunctionConverters._
@SpringBootApplication
@EnableBinding(value = Array(classOf[Processor]))
class ExampleStream {
@StreamListener
@Output(Source.OUTPUT)
def filter(@Input(Sink.INPUT) input: Flux[String]) : Flux[String] = {
val set = ('A' to 'Z').toSet
input
.filter(asJavaPredicate { m => set.contains(m.charAt(0)) })
.map( asJavaFunction { m => m.toUpperCase } )
}
}
object ExampleStream extends App {
SpringApplication.run(classOf[ExampleStream], args :_* )
}
开发者ID:kzarzycki,项目名称:spring-cloud-stream-example,代码行数:30,代码来源:ExampleStream.scala
示例5: ApplicationBoot
//设置package包名称以及导入依赖的类
package com.github.yingzhuo.dubbo.example.consumer
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.{Configuration, ImportResource}
object ApplicationBoot extends App {
SpringApplication.run(classOf[ApplicationBoot], args: _*)
}
@SpringBootApplication
class ApplicationBoot
@Configuration
@ImportResource(Array("classpath*:/dubbo/*.xml"))
class ApplicationBootConfigDubbo
@Configuration
class ApplicationBootConfigJackson {
@Autowired(required = false)
def configObjectMapper(objectMapper: ObjectMapper): Unit = {
objectMapper.registerModules(DefaultScalaModule)
}
}
开发者ID:yingzhuo,项目名称:dubbo-examples,代码行数:32,代码来源:ApplicationBoot.scala
示例6: ConfigClient
//设置package包名称以及导入依赖的类
package com.getindata.examples.spring
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
@SpringBootApplication
class ConfigClient @Autowired() (config: Config) {
@Bean
@ConditionalOnProperty(name = Array("serializer"), havingValue = "json")
def jsonSerializer = new JsonSerializer
@Bean
@ConditionalOnProperty(name = Array("serializer"), havingValue = "xml")
def xmlSerializer = new XmlSerializer
}
object ConfigClient extends App {
SpringApplication.run(classOf[ConfigClient], args: _*)
}
开发者ID:kzarzycki,项目名称:spring-cloud-scala,代码行数:25,代码来源:ConfigClient.scala
示例7: TweetsGatherer
//设置package包名称以及导入依赖的类
package com.github.tweets
import java.io.File
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.tweets.data.ProjectDataGatherer
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.{ApplicationArguments, ApplicationRunner, SpringApplication}
import org.springframework.context.annotation.ComponentScan
import scala.collection.JavaConversions._
@SpringBootApplication
@ComponentScan(Array("com.github.tweets"))
private class TweetsGatherer extends ApplicationRunner {
final val ConsoleOutputLocation = "console"
@Autowired
val projectDataGatherer: ProjectDataGatherer = null
@Autowired
val objectMapper: ObjectMapper = null
override def run(applicationArguments: ApplicationArguments): Unit = {
val searchKeyword = expectSearchKeyword(applicationArguments)
val outputLocation = expectOutputLocation(applicationArguments)
val result = projectDataGatherer.gatherProjectData(searchKeyword)
if (outputLocation == ConsoleOutputLocation)
objectMapper.writeValue(System.out, result)
else
objectMapper.writeValue(new File(outputLocation), result)
}
private def expectParam(applicationArguments: ApplicationArguments)(paramName: String)(defaultValue: => String) = {
if (applicationArguments.containsOption(paramName))
applicationArguments.getOptionValues(paramName).head
else
defaultValue
}
private def expectSearchKeyword(applicationArguments: ApplicationArguments) =
expectParam(applicationArguments)("keyword")(throw new RuntimeException("expected 'keyword' argument"))
private def expectOutputLocation(applicationArguments: ApplicationArguments) =
expectParam(applicationArguments)("output")(ConsoleOutputLocation)
}
object TweetsGatherer {
def main(args: Array[String]): Unit =
SpringApplication.run(classOf[TweetsGatherer], args: _*)
}
开发者ID:andrei-l,项目名称:tweets-for-github-projects-gatherer,代码行数:56,代码来源:TweetsGatherer.scala
示例8: Application
//设置package包名称以及导入依赖的类
package hello
import java.sql.ResultSet
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.jdbc.core.{JdbcTemplate, RowMapper}
import collection.JavaConverters._
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
@SpringBootApplication
class Application extends CommandLineRunner {
@Autowired
var jdbcTemplate: JdbcTemplate = _
val log: Logger = LoggerFactory.getLogger(classOf[Application])
override def run(args: String*): Unit = {
log.info("Creating tables")
jdbcTemplate.execute("DROP TABLE customers IF EXISTS")
jdbcTemplate.execute("CREATE TABLE customers(" +
"id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))")
val splitUpNames = ListBuffer("John Woo", "Jeff Dean", "Josh Bloch", "Josh Long").map(_.split(" "))
splitUpNames.foreach(name => log.info("Inserting customer record for %s %s".format(name(0), name(1))))
jdbcTemplate.batchUpdate("INSERT INTO customers(first_name, last_name) VALUES (?,?)", splitUpNames.asInstanceOf[mutable.Buffer[Array[AnyRef]]].asJava)
log.info("Querying for customer records where first_name = 'Josh':")
jdbcTemplate.query(
"SELECT id, first_name, last_name FROM customers WHERE first_name = ?",
Array("Josh").asInstanceOf[Array[AnyRef]],
// no Java 8 Lambda support in Scala pre 2.12
new RowMapper[Customer]{
override def mapRow(rs: ResultSet, rowNum: Int): Customer = new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name"))
})
// Works in Scala 2.12
// (rs: ResultSet, rowNum: Int) => new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")) )
.asScala.foreach((customer:Customer) => log.info(customer.toString))
}
}
object Application extends App {
SpringApplication.run(classOf[Application], args:_*)
}
开发者ID:BernhardWenzel,项目名称:spring-scala-examples,代码行数:54,代码来源:Application.scala
示例9: Application
//设置package包名称以及导入依赖的类
package hello
import org.slf4j.{Logger, LoggerFactory}
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.{CommandLineRunner, SpringApplication}
import org.springframework.http.ResponseEntity
import org.springframework.util.concurrent.{ListenableFuture, ListenableFutureCallback, SuccessCallback}
import org.springframework.web.client.{AsyncRestTemplate, RestTemplate}
@SpringBootApplication
class Application extends CommandLineRunner{
val log: Logger = LoggerFactory.getLogger(classOf[Application])
override def run(args: String*): Unit = {
val restTemplate = new RestTemplate()
// synchronous version
val quote : Quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", classOf[Quote])
log.info(quote.toString)
// async version
val asyncRestTemplate = new AsyncRestTemplate()
val quoteFuture : ListenableFuture[ResponseEntity[Quote]] = asyncRestTemplate.getForEntity("http://gturnquist-quoters.cfapps.io/api/random", classOf[Quote])
quoteFuture.addCallback(new ListenableFutureCallback[ResponseEntity[Quote]]() {
override def onSuccess(entity : ResponseEntity[Quote]) : Unit = log.info("async: " + entity.getBody.toString)
override def onFailure(t : Throwable) : Unit = log.error("Async error", t)
})
}
}
object Application extends App {
SpringApplication.run(classOf[Application], args:_*)
}
开发者ID:BernhardWenzel,项目名称:spring-scala-examples,代码行数:35,代码来源:Application.scala
示例10: Application
//设置package包名称以及导入依赖的类
package hello
import org.springframework.boot.{CommandLineRunner, SpringApplication}
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.jms.core.JmsTemplate
import org.springframework.jms.core.MessageCreator
import org.springframework.util.FileSystemUtils
import javax.jms.{Message, Session, TextMessage}
import java.io.File
import org.springframework.beans.factory.annotation.Autowired
import scala.beans.BeanProperty
@SpringBootApplication
class Application extends CommandLineRunner {
@BeanProperty
@Autowired
val jmsTemplate : JmsTemplate = null
def run(args: String*) : Unit = {
// Clean out any ActiveMQ data from a previous run
FileSystemUtils.deleteRecursively(new File("activemq-data"))
// create message
val messageCreator : MessageCreator = new MessageCreator {
override def createMessage(session: Session): Message = session.createTextMessage("ping!")
}
val receiver: Runnable = new Runnable {
def run(): Unit ={
// synchronous reception
System.out.println("====> Waiting for new message.")
jmsTemplate.setReceiveTimeout(100)
jmsTemplate.receive("default") match {
case m:TextMessage => println("====> Synchronous reception: " + m.getText)
case _ => println("====> Synchronous reception: No message received")
}
}
}
new Thread(receiver).start()
// Send a message
System.out.println("====> Sending a new message.")
jmsTemplate.send("default", messageCreator)
}
}
object Application extends App {
SpringApplication.run(classOf[Application], args:_*)
}
开发者ID:BernhardWenzel,项目名称:spring-scala-examples,代码行数:54,代码来源:Application.scala
注:本文中的org.springframework.boot.autoconfigure.SpringBootApplication类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论