@Test public void assertExistsPrivateCtor() { reflections.getSubTypesOf(Object.class).stream() .filter(clazz -> !clazz.isAnnotationPresent(Configuration.class)) .filter(clazz -> !clazz.isAnnotationPresent(Component.class)) .filter(clazz -> !clazz.isAnnotationPresent(SpringBootApplication.class)) .filter(clazz -> !clazz.getName().endsWith("Test")) .filter(clazz -> !clazz.isInterface()) .filter(clazz -> Arrays.stream(clazz.getDeclaredFields()) .allMatch(field -> Modifier.isStatic(field.getModifiers()))) .forEach(clazz -> { System.out.println("Expecting class "+clazz.getName()+" to :"); System.out.print("\t-> be final "); assertThat(clazz).isFinal(); System.out.println("[*]"); System.out.print("\t-> have exactly one constructor "); Constructor<?>[] constructors = clazz.getDeclaredConstructors(); assertThat(constructors).hasSize(1); System.out.println("[*]"); System.out.print("\t-> and that this constructor is private "); assertThat(Modifier.isPrivate(constructors[0].getModifiers())); System.out.println("[*]"); }); }
private MediaContract createMediaContract() throws ServiceException { LOG.debug("createMediaContract called"); final com.microsoft.windowsazure.Configuration configuration = MediaConfiguration .configureWithOAuthAuthentication( MediaServicesProperties.MEDIA_SERVICE_URI, MediaServicesProperties.OAUTH_URI, mediaServicesProperties.getAccountName(), mediaServicesProperties.getAccountKey(), MediaServicesProperties.SCOPE); if (nonNull(mediaServicesProperties.getProxyHost()) && nonNull(mediaServicesProperties.getProxyPort())) { configuration.getProperties().put(PROPERTY_HTTP_PROXY_HOST, mediaServicesProperties.getProxyHost()); configuration.getProperties().put(PROPERTY_HTTP_PROXY_PORT, mediaServicesProperties.getProxyPort()); configuration.getProperties().put(PROPERTY_HTTP_PROXY_SCHEME, mediaServicesProperties.getProxyScheme()); } else if (nonNull(mediaServicesProperties.getProxyHost()) && isNull(mediaServicesProperties.getProxyPort())) { throw new ServiceException("Please Set Network Proxy port in application.properties"); } else if (nonNull(mediaServicesProperties.getProxyPort()) && isNull(mediaServicesProperties.getProxyHost())) { throw new ServiceException("Please Set Network Proxy host in application.properties"); } return MediaService.create(configuration); }
@Bean @Primary @SneakyThrows public JGitRepository jGitRepository(ApplicationProperties applicationProperties, HazelcastInstance hazelcastInstance) { return new JGitRepository(applicationProperties.getGit(), new ReentrantLock()) { @Override protected void initRepository(){}; @Override protected void pull(){}; @Override protected void commitAndPush(String commitMsg){}; @Override public List<com.icthh.xm.ms.configuration.domain.Configuration> findAll(){ return emptyList(); } }; }
public void start() throws Exception { org.apache.activemq.artemis.core.config.Configuration configuration = new ConfigurationImpl(); HashSet<TransportConfiguration> transports = new HashSet<>(); transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName())); configuration.setAcceptorConfigurations(transports); configuration.setSecurityEnabled(false); File targetDir = new File(System.getProperty("user.dir") + "/target"); configuration.setBrokerInstance(targetDir); ActiveMQServer temp = new ActiveMQServerImpl(configuration); temp.start(); server = temp; }
@Bean public TypeMapConfigurer<User, UserDto> userMapping() { return new TypeMapConfigurer<User, UserDto>() { @Override public org.modelmapper.config.Configuration getConfiguration() { return new InheritingConfiguration().setSkipNullEnabled(true); } @Override public void configure(TypeMap<User, UserDto> typeMap) { typeMap.addMapping(User::getAge, UserDto::setAge); typeMap.addMapping(User::getName, UserDto::setFirstName); typeMap.addMapping(User::getName, UserDto::setLastName); } }; }
private JsonDeserializer<io.redlink.smarti.model.config.Configuration > buildConfigurationDeserializer(ObjectMapper objectMapper) { return new JsonDeserializer<io.redlink.smarti.model.config.Configuration>() { @Override public io.redlink.smarti.model.config.Configuration deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { final TypeFactory tf = ctxt.getTypeFactory(); final MapLikeType smartiConfigType = tf.constructMapLikeType(Map.class, tf.constructType(String.class), tf.constructCollectionLikeType(List.class, ComponentConfiguration.class)); final io.redlink.smarti.model.config.Configuration configuration = new io.redlink.smarti.model.config.Configuration(); configuration.setConfig(objectMapper.readerFor(smartiConfigType).readValue(p, smartiConfigType)); return configuration; } }; }
/** * Can we re-use DSLContext as a Spring bean (singleton)? Yes, the Spring tutorial of * Jooq also does it that way, but only if we do not change anything about the * config after the init (which we don't do anyways) and if the ConnectionProvider * does not store any shared state (we use DataSourceConnectionProvider of Jooq, so no problem). * * Some sources and discussion: * - http://www.jooq.org/doc/3.6/manual/getting-started/tutorials/jooq-with-spring/ * - http://jooq-user.narkive.com/2fvuLodn/dslcontext-and-threads * - https://groups.google.com/forum/#!topic/jooq-user/VK7KQcjj3Co * - http://stackoverflow.com/questions/32848865/jooq-dslcontext-correct-autowiring-with-spring */ @Bean public DSLContext dslContext() { initDataSource(); Settings settings = new Settings() // Normally, the records are "attached" to the Configuration that created (i.e. fetch/insert) them. // This means that they hold an internal reference to the same database connection that was used. // The idea behind this is to make CRUD easier for potential subsequent store/refresh/delete // operations. We do not use or need that. .withAttachRecords(false) // To log or not to log the sql queries, that is the question .withExecuteLogging(CONFIG.getDb().isSqlLogging()); // Configuration for JOOQ org.jooq.Configuration conf = new DefaultConfiguration() .set(SQLDialect.MYSQL) .set(new DataSourceConnectionProvider(dataSource)) .set(settings); return DSL.using(conf); }
@Bean public GroupHeartbeatService groupHeartbeatService() throws BeansException, UnknownHostException { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); final AgentConfiguration conf = beanFactory .getBean(AgentConfiguration.class); long initialDelay = 10000L; long checkFrequency = configuration.getLong( AgentProperties.HEARTBEAT_FREQUENCY.toString(), 300000L); int port = (int) conf.getMonitoringPort(); AgentStatus status = beanFactory.getBean(AgentStatus.class); LOG.info("USING status: " + status); GroupHeartbeatService service = new GroupHeartbeatService( beanFactory.getBean(GroupKeeper.class), Group.GroupStatus.Type.AGENT, status, port, initialDelay, checkFrequency, 10000L, beanFactory.getBean(StatusExtrasBuilder.class)); return service; }
@Bean public LogRolloverCheck logRolloverCheck() { org.apache.commons.configuration.Configuration conf = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); long rolloverTime = conf.getLong( CollectorProperties.WRITER.LOG_ROTATE_TIME.toString(), (Long) CollectorProperties.WRITER.LOG_ROTATE_TIME .getDefaultValue()); long inactiveTime = conf.getLong( CollectorProperties.WRITER.LOG_ROTATE_INACTIVE_TIME.toString(), (Long) CollectorProperties.WRITER.LOG_ROTATE_INACTIVE_TIME .getDefaultValue()); long logSizeMb = conf .getLong(CollectorProperties.WRITER.LOG_SIZE_MB.toString(), (Long) CollectorProperties.WRITER.LOG_SIZE_MB .getDefaultValue()); LOG.info("Using LogRollover: inactiveTime: " + inactiveTime + " rolloverTime: " + rolloverTime + " logSizeMb: " + logSizeMb); return new SimpleLogRolloverCheck(rolloverTime, logSizeMb, inactiveTime); }
@Bean public CompressionPoolFactory compressionPoolFactory() { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); int decompressorPoolSize = configuration .getInt(CollectorProperties.WRITER.COLLECTOR_DECOMPRESSOR_POOLSIZE .toString(), (Integer) CollectorProperties.WRITER.COLLECTOR_DECOMPRESSOR_POOLSIZE .getDefaultValue()); int compressorPoolSize = configuration .getInt(CollectorProperties.WRITER.COLLECTOR_COMPRESSOR_POOLSIZE .toString(), (Integer) CollectorProperties.WRITER.COLLECTOR_COMPRESSOR_POOLSIZE .getDefaultValue()); return new CompressionPoolFactoryImpl(decompressorPoolSize, compressorPoolSize, beanFactory.getBean(CollectorStatus.class)); }
@Bean public StatusExtrasBuilder getStatusExtrasBuilder() { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); String baseDir = configuration.getString( CollectorProperties.WRITER.BASE_DIR.toString(), CollectorProperties.WRITER.BASE_DIR.getDefaultValue() .toString()); return new StatusExtrasBuilder( beanFactory.getBean(CollectorStatus.class), baseDir, (CounterMetric) beanFactory .getBean("connectionsReceivedMetric"), (CounterMetric) beanFactory .getBean("connectionsProcessedMetric"), (CounterMetric) beanFactory.getBean("kilobytesWrttenMetric"), (CounterMetric) beanFactory.getBean("errorsMetric")); }
@Bean public OrphanedFilesCheck OrphanedFilesCheck() { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); String baseDir = configuration.getString( CollectorProperties.WRITER.BASE_DIR.toString(), CollectorProperties.WRITER.BASE_DIR.getDefaultValue() .toString()); long lowerMod = configuration.getLong( CollectorProperties.WRITER.ORPHANED_FILE_LOWER_MODE.toString(), (Long) CollectorProperties.WRITER.ORPHANED_FILE_LOWER_MODE .getDefaultValue()); File file = new File(baseDir); return new OrphanedFilesCheckImpl(file, beanFactory.getBean(LogRolloverCheck.class), beanFactory.getBean(LogFileNameExtractor.class), beanFactory.getBean(LogRollover.class), beanFactory.getBean( FileOutputStreamPoolFactory.class).getPoolForKey( "orphanedFiles"), lowerMod); }
@Bean public LogFileNameExtractor logFileNameExtractor() throws Exception { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); String cls = configuration .getString(CollectorProperties.WRITER.LOG_NAME_EXTRACTOR .toString()); LogFileNameExtractor nameExtractor = null; if (cls == null) { String keys = configuration.getString( CollectorProperties.WRITER.LOG_NAME_KEYS.toString(), CollectorProperties.WRITER.LOG_NAME_KEYS.getDefaultValue() .toString()); String[] splits = keys.split(","); nameExtractor = new DateHourFileNameExtractor(splits); } else { nameExtractor = (LogFileNameExtractor) Thread.currentThread() .getContextClassLoader().loadClass(cls).newInstance(); } return nameExtractor; }
/** * Configures a restlet ping component * * @return */ @Bean public Component restletPingComponent() { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); Component component = new Component(); component.getServers().add( org.restlet.data.Protocol.HTTP, configuration.getInt(CollectorProperties.WRITER.PING_PORT .toString(), (Integer) CollectorProperties.WRITER.PING_PORT .getDefaultValue())); component.getDefaultHost().attach(restletPingApplication()); return component; }
@Bean public LockTimeoutCheckAppService lockTimeoutCheckAppService() { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); long lockTimeoutPeriod = configuration .getLong( CoordinationProperties.PROP.COORDINATION_LOCK_TIMEOUTCHECK_PERIOD .toString(), (Long) CoordinationProperties.PROP.COORDINATION_LOCK_TIMEOUTCHECK_PERIOD .getDefaultValue()); long lockTimeout = configuration.getLong( CoordinationProperties.PROP.COORDINATION_LOCK_TIMEOUT .toString(), (Long) CoordinationProperties.PROP.COORDINATION_LOCK_TIMEOUT .getDefaultValue()); return new LockTimeoutCheckAppService(lockTimeoutPeriod, lockTimeout, beanFactory.getBean(LockMemory.class)); }
@Bean public CoordinationServer coordinationServer() { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); int lockPort = configuration.getInt( CoordinationProperties.PROP.COORDINATION_LOCK_PORT.toString(), (Integer) CoordinationProperties.PROP.COORDINATION_LOCK_PORT .getDefaultValue()); int releaseLockPort = configuration .getInt(CoordinationProperties.PROP.COORDINATION_UNLOCK_PORT .toString(), (Integer) CoordinationProperties.PROP.COORDINATION_UNLOCK_PORT .getDefaultValue()); return new CoordinationServerImpl(lockPort, releaseLockPort, beanFactory.getBean(CoordinationLockHandler.class), beanFactory.getBean( CoordinationUnLockHandler.class), beanFactory.getBean( MetricChannel.class)); }
@Bean @Lazy public CoordinationLockHandler coordinationLockHandler() { org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); int port = configuration.getInt( CoordinationProperties.PROP.LOCK_HOLDER_PING_PORT.toString(), (Integer) CoordinationProperties.PROP.LOCK_HOLDER_PING_PORT .getDefaultValue()); long lockTimeout = configuration.getLong( CoordinationProperties.PROP.COORDINATION_LOCK_TIMEOUT .toString(), (Long) CoordinationProperties.PROP.COORDINATION_LOCK_TIMEOUT .getDefaultValue()); return new CoordinationLockHandler( beanFactory.getBean(CoordinationStatus.class), beanFactory.getBean(LockMemory.class), beanFactory.getBean(HazelcastFileTrackerStorage.class), port, lockTimeout, beanFactory.getBean(FileTrackerHistoryMemory.class)); }
@Bean public StatusCleanoutService statusCleanoutService() throws Exception { // default once day org.apache.commons.configuration.Configuration configuration = beanFactory .getBean(org.apache.commons.configuration.Configuration.class); FileStatusCleanoutManager fileStatusCleanoutManager = beanFactory .getBean(FileStatusCleanoutManager.class); int statusCleanoutInterval = configuration .getInt(CoordinationProperties.PROP.STATUS_CLEANOUT_INTERVAL .toString(), (Integer) CoordinationProperties.PROP.STATUS_CLEANOUT_INTERVAL .getDefaultValue()); StatusCleanoutService service = new StatusCleanoutService( fileStatusCleanoutManager, 10, statusCleanoutInterval); return service; }
@Bean @ConditionalOnMissingBean(org.jooq.Configuration.class) public DefaultConfiguration jooqConfiguration() { DefaultConfiguration configuration = new DefaultConfiguration(); if (this.properties.getSqlDialect() != null) { configuration.set(this.properties.getSqlDialect()); } configuration.set(this.connectionProvider); if (this.transactionProvider != null) { configuration.set(this.transactionProvider); } if (this.recordMapperProvider != null) { configuration.set(this.recordMapperProvider); } if (this.settings != null) { configuration.set(this.settings); } configuration.set(this.recordListenerProviders); configuration.set(this.executeListenerProviders); configuration.set(this.visitListenerProviders); return configuration; }
@Test public void embeddedConnectionFactory() { load(EmptyConfiguration.class, "spring.hornetq.mode:embedded"); HornetQProperties properties = this.context.getBean(HornetQProperties.class); assertThat(properties.getMode()).isEqualTo(HornetQMode.EMBEDDED); assertThat(this.context.getBeansOfType(EmbeddedJMS.class)).hasSize(1); org.hornetq.core.config.Configuration configuration = this.context .getBean(org.hornetq.core.config.Configuration.class); assertThat(configuration.isPersistenceEnabled()).isFalse(); assertThat(configuration.isSecurityEnabled()).isFalse(); HornetQConnectionFactory connectionFactory = this.context .getBean(HornetQConnectionFactory.class); assertInVmConnectionFactory(connectionFactory); }
private Set<AnnotationMetadata> findConfigurationClasses() throws IOException { Set<AnnotationMetadata> configurationClasses = new HashSet<AnnotationMetadata>(); Resource[] resources = this.resolver.getResources("classpath*:" + getClass().getPackage().getName().replace(".", "/") + "/**/*.class"); for (Resource resource : resources) { if (!isTestClass(resource)) { MetadataReader metadataReader = new SimpleMetadataReaderFactory() .getMetadataReader(resource); AnnotationMetadata annotationMetadata = metadataReader .getAnnotationMetadata(); if (annotationMetadata.getAnnotationTypes() .contains(Configuration.class.getName())) { configurationClasses.add(annotationMetadata); } } } return configurationClasses; }
@Bean(name="freeMarkerCfg") public freemarker.template.Configuration freemarkerConfig() throws IOException { freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_25); cfg.setDirectoryForTemplateLoading(new File(templateFolder)); // cfg.setClassForTemplateLoading(this.getClass(), "templates"); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); return cfg; }
@Bean public FreeMarkerConfigurer configureFreemarker() { FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); Properties settings = new Properties(); settings.setProperty(freemarker.template.Configuration.TEMPLATE_EXCEPTION_HANDLER_KEY, "rethrow"); freeMarkerConfigurer.setFreemarkerSettings(settings); freeMarkerConfigurer.setTemplateLoaderPath(FreeMarkerProperties.DEFAULT_TEMPLATE_LOADER_PATH); return freeMarkerConfigurer; }
protected boolean isCandidate(MetadataReader metadataReader) throws ClassNotFoundException { try { Class<?> c = forName(metadataReader.getClassMetadata().getClassName()); if (c.getAnnotation(Configuration.class) != null) { return true; } } catch (Throwable e) { LOGGER.debug("error {}", e); } return false; }
private void validateIsConfigurationClass(Class<?> configurationClass) { boolean isConfigClass = false; for(Annotation annotation : configurationClass.getAnnotations()) { Class<? extends Annotation> type = annotation.annotationType(); if(Configuration.class.equals(type)) { isConfigClass = true; } } if(!isConfigClass) { throw new IllegalArgumentException("not a spring configuration class"); } }
private static String getKey(org.apache.hadoop.conf.Configuration conf, String keyType) { checkNotNull(conf, "conf cannot be null"); checkNotNull(keyType, "KeyType cannot be null"); try { char[] key = conf.getPassword(keyType); if (key == null) { throw new IllegalStateException(format("Unable to get value of '%s'", keyType)); } return new String(key); } catch (IOException e) { throw new IllegalStateException(format("Error getting key for '%s' from credential provider", keyType), e); } }
@Bean(name = "cleanUpCronTriggerFactoryBean") public CronTriggerFactoryBean cronTriggerFactoryBean() { com.sap.cloud.lm.sl.cf.core.util.Configuration configuration = com.sap.cloud.lm.sl.cf.core.util.Configuration.getInstance(); CronTriggerFactoryBean factory = new CronTriggerFactoryBean(); factory.setJobDetail(jobDetailFactoryBean().getObject()); factory.setCronExpression(configuration.getCronExpressionForOldData()); factory.setGroup(TRIGGER_GROUP); factory.setName(CLEAN_UP_TRIGGER_NAME); return factory; }
private ServiceBusContract createServiceBusContract() { LOG.debug("createServiceBusContract start..."); ServiceBusContract service = null; if (properties.getNamespaceName() != null) { com.microsoft.windowsazure.Configuration config = new com.microsoft.windowsazure.Configuration(); String connectionString = properties.buildServiceBusConnectString(); ServiceBusConfiguration.configureWithConnectionString(null, config, connectionString); service = ServiceBusService.create(config); } return service; }
@Bean public freemarker.template.Configuration configuration() { freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_26); cfg.setClassForTemplateLoading(this.getClass(), "/templates"); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); return cfg; }
@Bean public TypeMapConfigurer<User, UserDto> userMapping() { return new TypeMapConfigurer<User, UserDto>() { @Override public org.modelmapper.config.Configuration getConfiguration() { return new InheritingConfiguration().setSkipNullEnabled(true); } @Override public String getTypeMapName() { return "testName"; } @Override public void configure(TypeMap<User, UserDto> typeMap) { typeMap.addMapping(User::getAge, UserDto::setAge); typeMap.addMapping(User::getName, UserDto::setFirstName); typeMap.addMapping(User::getName, UserDto::setLastName); } }; }
@Bean public ConfigurationConfigurer mapperConfiguration() { return new ConfigurationConfigurer() { @Override public void configure(org.modelmapper.config.Configuration configuration) { configuration.setSkipNullEnabled(true); } }; }
@Bean public twitter4j.conf.Configuration configuration(final Environment environment) { final ConfigurationBuilder cb = new ConfigurationBuilder(); final String consumerKey = environment.getProperty("twitter.consumerKey"); final String consumerSecret = environment.getProperty("twitter.consumerSecret"); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthConsumerKey(consumerKey); return cb.build(); }
@Bean public DSLContext getDSLContext() { HikariDataSource hikariDataSource = new HikariDataSource(); hikariDataSource.setJdbcUrl(environment.getProperty("spring.datasource.url")); hikariDataSource.setUsername(environment.getProperty("spring.datasource.username")); hikariDataSource.setPassword(environment.getProperty("spring.datasource.password")); ConnectionProvider connectionProvider = new DataSourceConnectionProvider(hikariDataSource); org.jooq.Configuration configuration = new DefaultConfiguration().set(connectionProvider).set(SQLDialect.MYSQL); return DSL.using(configuration); }
@Bean(destroyMethod="shutdown") public net.sf.ehcache.CacheManager ehCacheManager() { CacheConfiguration cacheConfiguration = new CacheConfiguration(); cacheConfiguration.setName("categoryCache"); cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); cacheConfiguration.setMaxEntriesLocalHeap(1000); net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); //config.addCache(cacheConfiguration); config.defaultCache(cacheConfiguration); return net.sf.ehcache.CacheManager.newInstance(config); }
private ObjectMapper registerSmartiConfigModule(ObjectMapper objectMapper) { SimpleModule smartiConfigModule = new SimpleModule(); smartiConfigModule.addSerializer(io.redlink.smarti.model.config.Configuration.class, buildConfigurationSerializer(objectMapper)); smartiConfigModule.addDeserializer(io.redlink.smarti.model.config.Configuration.class, buildConfigurationDeserializer(objectMapper)); objectMapper.registerModule(smartiConfigModule); return objectMapper; }
private JsonSerializer<io.redlink.smarti.model.config.Configuration > buildConfigurationSerializer(ObjectMapper objectMapper) { return new JsonSerializer<io.redlink.smarti.model.config.Configuration >() { @Override public void serialize(io.redlink.smarti.model.config.Configuration value, JsonGenerator jgen, SerializerProvider provider) throws IOException { final TypeFactory tf = provider.getTypeFactory(); final MapLikeType smartiConfigType = tf.constructMapLikeType(Map.class, tf.constructType(String.class), tf.constructCollectionLikeType(List.class, ComponentConfiguration.class)); objectMapper.writerFor(smartiConfigType).writeValue(jgen, value.getConfig()); } }; }
@Bean(name = "sqlSessionFactory") @ConditionalOnMissingBean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); factory.setDataSource(dataSource); factory.setVfs(SpringBootVFS.class); if (StringUtils.hasText(this.properties.getConfigLocation())) { factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation())); } org.apache.ibatis.session.Configuration configuration = this.properties.getConfiguration(); if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) { configuration = new org.apache.ibatis.session.Configuration(); } factory.setConfiguration(configuration); if (this.properties.getConfigurationProperties() != null) { factory.setConfigurationProperties(this.properties.getConfigurationProperties()); } if (!ObjectUtils.isEmpty(this.interceptors)) { factory.setPlugins(this.interceptors); } if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) { factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage()); } if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) { factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage()); } if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) { factory.setMapperLocations(this.properties.resolveMapperLocations()); } return factory.getObject(); }
void build() { ApplicationContext context; ConfigurableListableBeanFactory beanFactory; if (javaConfig != null && javaConfig.isAnnotationPresent(Configuration.class)) { context = new AnnotationConfigApplicationContext(javaConfig); beanFactory = ((AnnotationConfigApplicationContext) context).getBeanFactory(); } else { context = new ClassPathXmlApplicationContext(configLocation); beanFactory = ((ClassPathXmlApplicationContext) context).getBeanFactory(); } beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); ApplicationHelper.getInstance().addApplicationContext(context); }