Search in sources :

Example 1 with MissingBean

use of cn.taketoday.context.annotation.MissingBean in project today-infrastructure by TAKETODAY.

the class MybatisAutoConfiguration method sqlSessionFactory.

@MissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setVfs(ResourceLoaderVFS.class);
    if (StringUtils.hasText(properties.getConfigLocation())) {
        factory.setConfigLocation(resourceLoader.getResource(properties.getConfigLocation()));
    }
    applyConfiguration(factory);
    if (properties.getConfigurationProperties() != null) {
        factory.setConfigurationProperties(properties.getConfigurationProperties());
    }
    if (StringUtils.isNotEmpty(properties.getTypeAliasesPackage())) {
        factory.setTypeAliasesPackage(properties.getTypeAliasesPackage());
    }
    if (properties.getTypeAliasesSuperType() != null) {
        factory.setTypeAliasesSuperType(properties.getTypeAliasesSuperType());
    }
    if (StringUtils.isNotEmpty(properties.getTypeHandlersPackage())) {
        factory.setTypeHandlersPackage(properties.getTypeHandlersPackage());
    }
    Resource[] mapperLocations = properties.resolveMapperLocations();
    if (ObjectUtils.isNotEmpty(mapperLocations)) {
        factory.setMapperLocations(mapperLocations);
    }
    interceptors.ifAvailable(factory::setPlugins);
    typeHandlers.ifAvailable(factory::setTypeHandlers);
    databaseIdProvider.ifAvailable(factory::setDatabaseIdProvider);
    Class<? extends LanguageDriver> defaultLanguageDriver = properties.getDefaultScriptingLanguageDriver();
    factory.setDefaultScriptingLanguageDriver(defaultLanguageDriver);
    languageDrivers.ifAvailable(languageDrivers -> {
        factory.setScriptingLanguageDrivers(languageDrivers);
        if (defaultLanguageDriver == null && languageDrivers.length == 1) {
            // override
            factory.setDefaultScriptingLanguageDriver(languageDrivers[0].getClass());
        }
    });
    applySqlSessionFactoryBeanCustomizers(factory);
    return factory.getObject();
}
Also used : Resource(cn.taketoday.core.io.Resource) SqlSessionFactoryBean(cn.taketoday.orm.mybatis.SqlSessionFactoryBean) ConditionalOnMissingBean(cn.taketoday.context.condition.ConditionalOnMissingBean) MissingBean(cn.taketoday.context.annotation.MissingBean)

Example 2 with MissingBean

use of cn.taketoday.context.annotation.MissingBean in project today-framework by TAKETODAY.

the class CrossOriginConfiguration method handlerCorsCustomizer.

@MissingBean
public HandlerCorsCustomizer handlerCorsCustomizer(CorsProcessor corsProcessor, ApplicationContext context) {
    HandlerCorsCustomizer customizer = new HandlerCorsCustomizer(corsProcessor);
    ExpressionEvaluator expressionEvaluator = context.getExpressionEvaluator();
    customizer.setExpressionEvaluator(expressionEvaluator);
    return customizer;
}
Also used : HandlerCorsCustomizer(cn.taketoday.web.registry.HandlerCorsCustomizer) ExpressionEvaluator(cn.taketoday.context.expression.ExpressionEvaluator) MissingBean(cn.taketoday.context.annotation.MissingBean)

Example 3 with MissingBean

use of cn.taketoday.context.annotation.MissingBean in project today-framework by TAKETODAY.

the class WebSocketConfig method annotationWebSocketHandlerBuilder.

@MissingBean(value = AnnotationWebSocketHandlerBuilder.class)
AnnotationWebSocketHandlerBuilder annotationWebSocketHandlerBuilder(List<EndpointParameterResolver> resolvers) {
    final AnnotationWebSocketHandlerBuilder handlerBuilder;
    if (ClassUtils.isPresent("jakarta.websocket.Session")) {
        handlerBuilder = new StandardAnnotationWebSocketHandlerBuilder();
    } else {
        handlerBuilder = new AnnotationWebSocketHandlerBuilder();
    }
    handlerBuilder.registerDefaultResolvers();
    handlerBuilder.addResolvers(resolvers);
    // @since 4.0 trimToSize
    handlerBuilder.trimToSize();
    return handlerBuilder;
}
Also used : StandardAnnotationWebSocketHandlerBuilder(cn.taketoday.web.socket.annotation.StandardAnnotationWebSocketHandlerBuilder) StandardAnnotationWebSocketHandlerBuilder(cn.taketoday.web.socket.annotation.StandardAnnotationWebSocketHandlerBuilder) AnnotationWebSocketHandlerBuilder(cn.taketoday.web.socket.annotation.AnnotationWebSocketHandlerBuilder) MissingBean(cn.taketoday.context.annotation.MissingBean)

Example 4 with MissingBean

use of cn.taketoday.context.annotation.MissingBean in project today-framework by TAKETODAY.

the class WebSocketConfig method annotationWebSocketHandlerBuilder.

@MissingBean(value = AnnotationWebSocketHandlerBuilder.class)
AnnotationWebSocketHandlerBuilder annotationWebSocketHandlerBuilder(List<EndpointParameterResolver> resolvers, List<WebSocketConfiguration> configurers) {
    AnnotationWebSocketHandlerBuilder handlerBuilder;
    if (ClassUtils.isPresent("jakarta.websocket.Session")) {
        handlerBuilder = new StandardAnnotationWebSocketHandlerBuilder();
    } else {
        handlerBuilder = new AnnotationWebSocketHandlerBuilder();
    }
    // configure EndpointParameterResolver
    for (WebSocketConfiguration configurer : configurers) {
        configurer.configureEndpointParameterResolvers(resolvers);
    }
    handlerBuilder.registerDefaultResolvers();
    handlerBuilder.addResolvers(resolvers);
    // @since 4.0 trimToSize
    handlerBuilder.trimToSize();
    return handlerBuilder;
}
Also used : StandardAnnotationWebSocketHandlerBuilder(cn.taketoday.web.socket.annotation.StandardAnnotationWebSocketHandlerBuilder) StandardAnnotationWebSocketHandlerBuilder(cn.taketoday.web.socket.annotation.StandardAnnotationWebSocketHandlerBuilder) AnnotationWebSocketHandlerBuilder(cn.taketoday.web.socket.annotation.AnnotationWebSocketHandlerBuilder) MissingBean(cn.taketoday.context.annotation.MissingBean)

Example 5 with MissingBean

use of cn.taketoday.context.annotation.MissingBean in project today-framework by TAKETODAY.

the class MybatisAutoConfiguration method sqlSessionFactory.

@MissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setVfs(ResourceLoaderVFS.class);
    if (StringUtils.hasText(properties.getConfigLocation())) {
        factory.setConfigLocation(resourceLoader.getResource(properties.getConfigLocation()));
    }
    applyConfiguration(factory);
    if (properties.getConfigurationProperties() != null) {
        factory.setConfigurationProperties(properties.getConfigurationProperties());
    }
    if (StringUtils.isNotEmpty(properties.getTypeAliasesPackage())) {
        factory.setTypeAliasesPackage(properties.getTypeAliasesPackage());
    }
    if (properties.getTypeAliasesSuperType() != null) {
        factory.setTypeAliasesSuperType(properties.getTypeAliasesSuperType());
    }
    if (StringUtils.isNotEmpty(properties.getTypeHandlersPackage())) {
        factory.setTypeHandlersPackage(properties.getTypeHandlersPackage());
    }
    Resource[] mapperLocations = properties.resolveMapperLocations();
    if (ObjectUtils.isNotEmpty(mapperLocations)) {
        factory.setMapperLocations(mapperLocations);
    }
    interceptors.ifAvailable(factory::setPlugins);
    typeHandlers.ifAvailable(factory::setTypeHandlers);
    databaseIdProvider.ifAvailable(factory::setDatabaseIdProvider);
    Class<? extends LanguageDriver> defaultLanguageDriver = properties.getDefaultScriptingLanguageDriver();
    factory.setDefaultScriptingLanguageDriver(defaultLanguageDriver);
    languageDrivers.ifAvailable(languageDrivers -> {
        factory.setScriptingLanguageDrivers(languageDrivers);
        if (defaultLanguageDriver == null && languageDrivers.length == 1) {
            // override
            factory.setDefaultScriptingLanguageDriver(languageDrivers[0].getClass());
        }
    });
    applySqlSessionFactoryBeanCustomizers(factory);
    return factory.getObject();
}
Also used : Resource(cn.taketoday.core.io.Resource) SqlSessionFactoryBean(cn.taketoday.orm.mybatis.SqlSessionFactoryBean) ConditionalOnMissingBean(cn.taketoday.context.condition.ConditionalOnMissingBean) MissingBean(cn.taketoday.context.annotation.MissingBean)

Aggregations

MissingBean (cn.taketoday.context.annotation.MissingBean)7 AnnotationWebSocketHandlerBuilder (cn.taketoday.web.socket.annotation.AnnotationWebSocketHandlerBuilder)3 StandardAnnotationWebSocketHandlerBuilder (cn.taketoday.web.socket.annotation.StandardAnnotationWebSocketHandlerBuilder)3 ConditionalOnMissingBean (cn.taketoday.context.condition.ConditionalOnMissingBean)2 Resource (cn.taketoday.core.io.Resource)2 SqlSessionFactoryBean (cn.taketoday.orm.mybatis.SqlSessionFactoryBean)2 ConditionalOnClass (cn.taketoday.context.condition.ConditionalOnClass)1 ExpressionEvaluator (cn.taketoday.context.expression.ExpressionEvaluator)1 HandlerCorsCustomizer (cn.taketoday.web.registry.HandlerCorsCustomizer)1 Configuration (jakarta.validation.Configuration)1 ValidationProvider (jakarta.validation.spi.ValidationProvider)1