• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Bean类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ConfigurationEntrypoint

//设置package包名称以及导入依赖的类
package com.sk.app.proxmock.application.configuration

import com.sk.app.proxmock.application.domain.Config
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ConfigurableApplicationContext
import org.springframework.context.annotation.{Bean, Configuration}


@Configuration
class ConfigurationEntrypoint {
  @Autowired
  val context: ConfigurableApplicationContext = null

  @Bean
  def startSetup(@Autowired config: Config): Object = {
    config.configure(context)
    new Object()
  }
} 
开发者ID:szymonkudzia,项目名称:proxmock,代码行数:20,代码来源:ConfigurationEntrypoint.scala


示例17: JacksonConfig

//设置package包名称以及导入依赖的类
package com.example.cloud.jackson

import com.fasterxml.jackson.databind.{Module, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.springframework.context.annotation.{Bean, Configuration}
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter


@Configuration
class JacksonConfig {
  @Bean
  def mappingJackson2HttpMessageConverter(objectMapper: ObjectMapper, defaultScalaModule: DefaultScalaModule) = {
    objectMapper.registerModule(defaultScalaModule)
    new MappingJackson2HttpMessageConverter(objectMapper)
  }

  @Bean
  def defaultScalaModule: Module = new DefaultScalaModule
} 
开发者ID:okharkovskyi,项目名称:scala-cloud-skeleton,代码行数:20,代码来源:JacksonConfig.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ReactConnector类代码示例发布时间:2022-05-23
下一篇:
Scala Either类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap