本文整理汇总了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
}
}
示例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
}
示例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()
}
}
}
示例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"
}
示例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"
}
示例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
}
}
示例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))
}
}
示例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)
}
}
示例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
)
}
}
示例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
}
}
示例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: _*)
}
示例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
}
示例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)))
}
}
示例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/"
}
}
示例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)
}