本文整理汇总了Scala中org.springframework.boot.SpringApplication类的典型用法代码示例。如果您正苦于以下问题:Scala SpringApplication类的具体用法?Scala SpringApplication怎么用?Scala SpringApplication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpringApplication类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: TestApp
//设置package包名称以及导入依赖的类
package k8sdnssky
import java.util.Properties
import k8sdnssky.App.AppConfig
import org.springframework.boot.SpringApplication
object TestApp {
def main(args: Array[String]): Unit = {
val app = new SpringApplication(classOf[AppConfig])
app.setDefaultProperties(loadDefaultProperties())
app.run(args: _*)
}
private def loadDefaultProperties(): Properties = {
val props = new Properties()
val stream = getClass.getResourceAsStream("/app-defaults.properties")
try {
props.load(stream)
props
} finally {
stream.close()
}
}
}
示例2: 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)
}
}
}
示例3: 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]
}
示例4: TestApp
//设置package包名称以及导入依赖的类
package k8sslbnginxing
import java.util.Properties
import k8sslbnginxing.App.AppConfig
import org.springframework.boot.SpringApplication
object TestApp {
def main(args: Array[String]): Unit = {
val app = new SpringApplication(classOf[AppConfig])
app.setDefaultProperties(loadDefaultProperties())
app.run(args: _*)
}
private def loadDefaultProperties(): Properties = {
val props = new Properties()
val stream = getClass.getResourceAsStream("/app-defaults.properties")
try {
props.load(stream)
props
} finally {
stream.close()
}
}
}
示例5: 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 :_* )
}
示例6: 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)
}
}
示例7: 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: _*)
}
示例8: 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: _*)
}
示例9: 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:_*)
}
示例10: 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:_*)
}
示例11: 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:_*)
}