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


Scala Bean类代码示例

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


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

示例1: OmegaWebApplicationConfig

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

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer
import org.springframework.web.servlet.config.annotation.EnableWebMvc
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import org.springframework.web.servlet.view.InternalResourceViewResolver
import org.springframework.web.servlet.view.JstlView

@Configuration("OmegaWebApplicationConfig")
@EnableWebMvc
@ComponentScan(basePackages = Array("com.omega.controllers"))
class OmegaWebApplicationConfig extends WebMvcConfigurerAdapter {
    
    override def addResourceHandlers(registry: ResourceHandlerRegistry): Unit = {
        // registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/META-INF/resources/webjars/").setCachePeriod(31556926)
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/").setCachePeriod(31556926)
    }

    override def configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer) {
        configurer.enable()
    }
    
    @Bean
    def theJspViewResolver(): InternalResourceViewResolver = {
        val viewResolver = new InternalResourceViewResolver
        viewResolver.setViewClass(classOf[JstlView])
        viewResolver.setPrefix("/WEB-INF/views/jsp/")
        viewResolver.setSuffix(".jsp")
        viewResolver.setOrder(1)
        viewResolver
    }
} 
开发者ID:milind-chawla,项目名称:Omega,代码行数:37,代码来源:OmegaWebApplicationConfig.scala

示例2: 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

示例3: 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

示例4: DBConfig

//设置package包名称以及导入依赖的类
package com.github.swwjf.config

import javax.persistence.EntityManagerFactory
import javax.sql.DataSource

import org.apache.commons.dbcp2.BasicDataSource
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties
import org.springframework.boot.context.properties.{ConfigurationProperties, EnableConfigurationProperties}
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder
import org.springframework.context.annotation.{Bean, Configuration, Primary}
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.orm.jpa.{JpaTransactionManager, LocalContainerEntityManagerFactoryBean}
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.annotation.EnableTransactionManagement

@Configuration
@EnableJpaRepositories(basePackages = Array(DBConfig.RootPackage))
@EnableTransactionManagement
@EnableConfigurationProperties(Array(classOf[JpaProperties]))
private class DBConfig {
  @Bean
  @ConfigurationProperties(prefix = "jdbc.datasource.ws")
  @Primary
  def wsDataSource(): DataSource =
    DataSourceBuilder
      .create()
      .`type`(classOf[BasicDataSource])
      .build()

  @Bean
  @Autowired
  def entityManagerFactory(builder: EntityManagerFactoryBuilder): LocalContainerEntityManagerFactoryBean =
    builder
      .dataSource(wsDataSource())
      .persistenceUnit("ws")
      .packages(DBConfig.RootPackage)
      .build()

  @Bean
  def transactionManager(entityManagerFactory: EntityManagerFactory): PlatformTransactionManager = {
    val txManager = new JpaTransactionManager()
    txManager.setEntityManagerFactory(entityManagerFactory)
    txManager
  }
}

private object DBConfig extends DBConstants

private sealed trait DBConstants {
  final val RootPackage = "com.github.swwjf"
} 
开发者ID:andrei-l,项目名称:scala-webapp-with-java-frameworks,代码行数:54,代码来源:DBConfig.scala

示例5: WSDBTestConfig

//设置package包名称以及导入依赖的类
package com.github.swwjf.config

import javax.sql.DataSource

import com.github.springtestdbunit.bean.{DatabaseConfigBean, DatabaseDataSourceConnectionFactoryBean}
import org.dbunit.database.DatabaseDataSourceConnection
import org.dbunit.ext.h2.H2DataTypeFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.{Bean, Configuration}

@Configuration
private class WSDBTestConfig {
  @Bean
  def databaseConfig(): DatabaseConfigBean = {
    val dbConfig = new DatabaseConfigBean()
    dbConfig.setDatatypeFactory(new H2DataTypeFactory())
    dbConfig
  }

  @Bean
  @Autowired
  def wsDBUnitDatabaseConnection(dataSource: DataSource, databaseConfigBean: DatabaseConfigBean): DatabaseDataSourceConnection = {
    val connectionFactoryBean: DatabaseDataSourceConnectionFactoryBean = new DatabaseDataSourceConnectionFactoryBean
    connectionFactoryBean.setDataSource(dataSource)
    connectionFactoryBean.setDatabaseConfig(databaseConfigBean)
    connectionFactoryBean.getObject
  }
}

private[swwjf] object WSDBTestConfig {
  final val ConnectionName = "wsDBUnitDatabaseConnection"
} 
开发者ID:andrei-l,项目名称:scala-webapp-with-java-frameworks,代码行数:33,代码来源:WSDBTestConfig.scala

示例6: GuavaConfiguration

//设置package包名称以及导入依赖的类
package edu.cmsandiga.examples.caching

import java.util.concurrent.TimeUnit

import com.google.common.cache.CacheBuilder
import org.springframework.cache.guava.GuavaCacheManager
import org.springframework.context.annotation.{Bean, Configuration}

@Configuration
class GuavaConfiguration {

  @Bean
  def guavaCache() ={
    val cacheManager = new GuavaCacheManager()
    cacheManager.setCacheBuilder(
      CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).maximumSize(100)
    )
    cacheManager
  }

} 
开发者ID:cmsandiga,项目名称:Spring-boot-scala,代码行数:22,代码来源:GuavaConfiguration.scala

示例7: SchedulerConfiguration

//设置package包名称以及导入依赖的类
package com.github.mkorman9.districron

import org.springframework.context.annotation.{Bean, Configuration}
import org.springframework.scheduling.TaskScheduler
import org.springframework.scheduling.annotation.{EnableAsync, EnableScheduling}
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler

@Configuration
@EnableScheduling
@EnableAsync
class SchedulerConfiguration {
  final val DefaultSchedulerThreadPool = 10

  @Bean
  def taskScheduler: TaskScheduler = {
    val scheduler = new ThreadPoolTaskScheduler()
    scheduler.setPoolSize(
      resolveEnvironmentProperty("SCHEDULER_THREAD_POOL", DefaultSchedulerThreadPool)
    )

    scheduler
  }

  private def resolveEnvironmentProperty(name: String, defaultValue: Int) = {
    Integer.valueOf(sys.env.getOrElse(name, "" + defaultValue))
  }
} 
开发者ID:mkorman9,项目名称:districron,代码行数:28,代码来源:SchedulerConfiguration.scala

示例8: SystemConfiguration

//设置package包名称以及导入依赖的类
package com.github.mkorman9.districron

import javax.sql.DataSource

import akka.actor.ActorSystem
import com.typesafe.config.{Config, ConfigFactory}
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
import org.springframework.context.annotation.{Bean, ComponentScan, Configuration}
import org.springframework.scheduling.annotation.EnableScheduling

import scala.slick.driver.MySQLDriver.simple._

@Configuration
@ComponentScan
@EnableScheduling
class SystemConfiguration {
  final val ActorSystemName = "DistricronSystem"

  @Bean
  def config: Config = {
    ConfigFactory.load()
  }

  @Bean
  def actorSystem(config: Config): ActorSystem = {
    ActorSystem(ActorSystemName, config)
  }

  @Bean
  def dataSource(config: Config): DataSource = {
    val hikariConfig = new HikariConfig()
    hikariConfig.setDriverClassName(config.getString("datasource.jdbc-driver-class"))
    hikariConfig.setJdbcUrl(config.getString("datasource.jdbc-url"))
    hikariConfig.setUsername(config.getString("datasource.jdbc-username"))
    hikariConfig.setPassword(config.getString("datasource.jdbc-password"))
    hikariConfig.setMaxLifetime(config.getInt("datasource.poll-max-lifetime"))
    hikariConfig.setLeakDetectionThreshold(config.getInt("datasource.poll-leak-detection-threshold"))

    new HikariDataSource(hikariConfig)
  }

  @Bean
  def databaseConnection(dataSource: DataSource): Database = {
    Database.forDataSource(dataSource)
  }
} 
开发者ID:mkorman9,项目名称:districron,代码行数:47,代码来源:SystemConfiguration.scala

示例9: ActorsConfiguration

//设置package包名称以及导入依赖的类
package com.github.mkorman9.districron

import akka.actor.{ActorRef, ActorSystem, Props}
import com.github.mkorman9.districron.actor.TasksHandlingActor
import com.github.mkorman9.districron.logic.{MessageSender, TasksManager}
import org.springframework.context.annotation.{Bean, Configuration}

@Configuration
class ActorsConfiguration {
  @Bean(Array(TasksHandlingActor.name))
  def tasksSchedulerActor(system: ActorSystem, tasksManager: TasksManager, messageSender: MessageSender): ActorRef = {
    system.actorOf(
      Props(classOf[TasksHandlingActor], tasksManager, messageSender),
      TasksHandlingActor.name
    )
  }
} 
开发者ID:mkorman9,项目名称:districron,代码行数:18,代码来源:ActorsConfiguration.scala

示例10: MockRestServer

//设置package包名称以及导入依赖的类
package com.atomist.rug.kind.http

import org.springframework.context.annotation.{Bean, Configuration, Primary}
import org.springframework.test.web.client.MockRestServiceServer
import org.springframework.web.client.{RestOperations, RestTemplate}

object MockRestServer {
  val restTemplate = new RestTemplate()
  val server = MockRestServiceServer.bindTo(restTemplate).build()
}

@Configuration
class MockRestConfig {

  @Bean
  @Primary
  def httpClientMock: RestOperations = {
    MockRestServer.restTemplate
  }
} 
开发者ID:atomist,项目名称:rug,代码行数:21,代码来源:MockRestConfig.scala

示例11: 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

示例12: getSessionFactory

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

import com.ntsdev.service.TestDataService
import org.neo4j.ogm.session.SessionFactory
import org.springframework.context.annotation.Bean
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager

trait GraphConfiguration {

  @Bean
  def getSessionFactory(neo4jConfig: org.neo4j.ogm.config.Configuration): SessionFactory = {
    new SessionFactory(neo4jConfig, "com.ntsdev.domain"){}
  }

  @Bean
  def transactionManager(sessionFactory: SessionFactory): Neo4jTransactionManager = {
    new Neo4jTransactionManager(sessionFactory)
  }

  @Bean
  def testDataService(): TestDataService = {
    new TestDataService()
  }

  def getNeo4jConfig: org.neo4j.ogm.config.Configuration

} 
开发者ID:neilshannon,项目名称:atlanta-scala-microservice,代码行数:28,代码来源:GraphConfiguration.scala

示例13: FlexMappingModule

//设置package包名称以及导入依赖的类
package yang.flexmapping

import akka.actor.{ActorRef, ActorRefFactory, Props}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.{Bean, Configuration}
import yang.flexmapping.enrich.{Enrich, EnrichActor, EnrichSimpleImpl}
import yang.flexmapping.process.FlemxMappingProcesserCreator


@Configuration
class FlexMappingModule {
  @Autowired
  var actorFactory: ActorRefFactory = null

  @Bean
  def flexMappingProcessor: FlemxMappingProcesserCreator = new FlemxMappingProcesserCreator

  @Autowired
  var userManagerActor: ActorRef = null

  @Bean
  def flexMappingActor: ActorRef = {
    actorFactory.actorOf(Props(new FlexMappingActor(flexMappingProcessor,userManagerActor)))
  }

  @Bean
  def enrich:Enrich=new EnrichSimpleImpl

  @Bean
  def enrichActor:ActorRef={
    actorFactory.actorOf(Props(new EnrichActor(enrich,flexMappingActor)))

  }

} 
开发者ID:wjingyao2008,项目名称:firsttry,代码行数:36,代码来源:FlexMappingModule.scala

示例14: WasSpringModule

//设置package包名称以及导入依赖的类
package yang.notification.was

import akka.actor.ActorRef
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.{Bean, Configuration}
import yang.notification.UserChangedNotifiable


@Configuration
class WasSpringModule {

  @Autowired
  var configuration: org.apache.commons.configuration2.Configuration = null

  @Autowired
  var sourceActor: ActorRef = null

  @Bean
  def registerInterface: UserChangedNotifiable = {
    new NotificationRegister(callBackHostName)
  }

  @Bean
  def notificationCallback: NotificationCallBack = {
    val callBack = new NotificationCallBack(callBackHostName, sourceActor)
    callBack.start()
    callBack
  }

  @Bean
  def callBackHostName: String = {
    val hostName = configuration.getString("com.oss.nsn.nbi.was.ndcallback.hostname")
    s"http://$hostName:8296/nd-callback/"
  }


} 
开发者ID:wjingyao2008,项目名称:firsttry,代码行数:38,代码来源:WasSpringModule.scala

示例15: AppConfig

//设置package包名称以及导入依赖的类
package com.github.tweets.config

import com.fasterxml.jackson.databind.{SerializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.springframework.context.annotation.{Bean, Configuration}
import org.springframework.http.converter.StringHttpMessageConverter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.web.client.RestTemplate

import scala.collection.JavaConversions._

@Configuration
private class AppConfig {
  @Bean
  def objectMapper(): ObjectMapper = {
    val om = new ObjectMapper()
    om.registerModule(DefaultScalaModule)
    om.enable(SerializationFeature.INDENT_OUTPUT)
    om
  }

  @Bean
  def restTemplate(jacksonMessageConverter: MappingJackson2HttpMessageConverter): RestTemplate = {
    val restTemplate = new RestTemplate()
    restTemplate.setMessageConverters(List(jacksonMessageConverter, new StringHttpMessageConverter))
    restTemplate
  }

  @Bean
  def jacksonMessageConverter(objectMapper: ObjectMapper) = new MappingJackson2HttpMessageConverter(objectMapper)
} 
开发者ID:andrei-l,项目名称:tweets-for-github-projects-gatherer,代码行数:32,代码来源:AppConfig.scala


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