Java Code Examples for org.springframework.util.ClassUtils#isPresent()
The following examples show how to use
org.springframework.util.ClassUtils#isPresent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtobufHttpMessageConverter.java From spring-analysis-note with MIT License | 6 votes |
ProtobufHttpMessageConverter(@Nullable ProtobufFormatSupport formatSupport, @Nullable ExtensionRegistry extensionRegistry) { if (formatSupport != null) { this.protobufFormatSupport = formatSupport; } else if (ClassUtils.isPresent("com.googlecode.protobuf.format.FormatFactory", getClass().getClassLoader())) { this.protobufFormatSupport = new ProtobufJavaFormatSupport(); } else if (ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", getClass().getClassLoader())) { this.protobufFormatSupport = new ProtobufJavaUtilSupport(null, null); } else { this.protobufFormatSupport = null; } setSupportedMediaTypes(Arrays.asList(this.protobufFormatSupport != null ? this.protobufFormatSupport.supportedMediaTypes() : new MediaType[] {PROTOBUF, TEXT_PLAIN})); this.extensionRegistry = (extensionRegistry == null ? ExtensionRegistry.newInstance() : extensionRegistry); }
Example 2
Source File: DoradoPreloadSpringApplicationRunListener.java From bdf3 with Apache License 2.0 | 6 votes |
@Override public void contextPrepared(ConfigurableApplicationContext applicationContext) { if (ClassUtils.isPresent("com.bstek.dorado.web.loader.DoradoLoader", this.getClass().getClassLoader())){ System.setProperty("doradoHome", "classpath:dorado-home/"); DoradoLoader doradoLoader = DoradoLoader.getInstance(); try { Context context = CommonContext.init(applicationContext); DoradoLoader.getInstance().setFailSafeContext(context); doradoLoader.preload(true);; } catch (Exception e) { e.printStackTrace(); } Set<String> sources = new LinkedHashSet<String>(); sources.addAll(doradoLoader .getContextLocations(false)); application.setSources(sources); } }
Example 3
Source File: RabbitAutoConfiguration.java From summerframework with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { appEnv = env; if (env.containsProperty(RABBIT_TRACE_LOG_TYPE_KEY)) { String type = env.getProperty(RABBIT_TRACE_LOG_TYPE_KEY); if (type.equals(RABBIT_TRACE_LOG_TYPE_FILE)) { AbstractTraceLog.setTraceLogger(Slf4jTraceLogger.instance); } else if (type.equals(RABBIT_TRACE_LOG_TYPE_MYSQL)) { AbstractTraceLog.setTraceLogger(new DatabaseMySQLTraceLogger(dataSource, capacity)); } else if (type.equals(RABBIT_TRACE_LOG_TYPE_NONE)) { AbstractTraceLog.setTraceLogger(NoopTraceLogger.instance); } } else { if (dataSource != null && ClassUtils.isPresent("com.mysql.jdbc.Driver", RabbitAutoConfiguration.class.getClassLoader())) { AbstractTraceLog.setTraceLogger(new DatabaseMySQLTraceLogger(dataSource, capacity)); } else { AbstractTraceLog.setTraceLogger(Slf4jTraceLogger.instance); } } }
Example 4
Source File: MBeanExportConfiguration.java From spring-analysis-note with MIT License | 5 votes |
@Nullable public static SpecificPlatform get() { ClassLoader classLoader = MBeanExportConfiguration.class.getClassLoader(); for (SpecificPlatform environment : values()) { if (ClassUtils.isPresent(environment.identifyingClass, classLoader)) { return environment; } } return null; }
Example 5
Source File: ReactiveAdapterRegistry.java From java-technology-stack with MIT License | 5 votes |
/** * Create a registry and auto-register default adapters. * @see #getSharedInstance() */ public ReactiveAdapterRegistry() { ClassLoader classLoader = ReactiveAdapterRegistry.class.getClassLoader(); // Reactor boolean reactorRegistered = false; if (ClassUtils.isPresent("reactor.core.publisher.Flux", classLoader)) { new ReactorRegistrar().registerAdapters(this); reactorRegistered = true; } this.reactorPresent = reactorRegistered; // RxJava1 if (ClassUtils.isPresent("rx.Observable", classLoader) && ClassUtils.isPresent("rx.RxReactiveStreams", classLoader)) { new RxJava1Registrar().registerAdapters(this); } // RxJava2 if (ClassUtils.isPresent("io.reactivex.Flowable", classLoader)) { new RxJava2Registrar().registerAdapters(this); } // Java 9+ Flow.Publisher if (ClassUtils.isPresent("java.util.concurrent.Flow.Publisher", classLoader)) { new ReactorJdkFlowAdapterRegistrar().registerAdapter(this); } // If not present, do nothing for the time being... // We can fall back on "reactive-streams-flow-bridge" (once released) }
Example 6
Source File: ExtTargeter.java From onetwo with Apache License 2.0 | 5 votes |
@Override public void afterPropertiesSet() throws Exception { if (ClassUtils.isPresent(CLASS_HYSTRIX_FEIGN, ClassUtils.getDefaultClassLoader())) { cloudTargeter = new HystrixTargeter(); } else { cloudTargeter = new DefaultTargeter(); } }
Example 7
Source File: MessageUtils.java From spring-cloud-function with Apache License 2.0 | 5 votes |
/** * Convert a message from the handler into one that is safe to consume in the caller's * class loader. If the handler is a wrapper for a function in an isolated class * loader, then the message will be created with the target class loader (therefore * the {@link Message} class must be on the classpath of the target class loader). * @param handler the function that generated the message * @param message the message to convert * @return a message with the correct class loader */ public static Message<?> unpack(Object handler, Object message) { if (handler instanceof FluxWrapper) { handler = ((FluxWrapper<?>) handler).getTarget(); } if (!(handler instanceof Isolated)) { if (message instanceof Message) { return (Message<?>) message; } return MessageBuilder.withPayload(message).build(); } ClassLoader classLoader = ((Isolated) handler).getClassLoader(); Class<?> type = ClassUtils.isPresent(Message.class.getName(), classLoader) ? ClassUtils.resolveClassName(Message.class.getName(), classLoader) : null; Object payload; Map<String, Object> headers; if (type != null && type.isAssignableFrom(message.getClass())) { Method getPayload = ClassUtils.getMethod(type, "getPayload"); Method getHeaders = ClassUtils.getMethod(type, "getHeaders"); payload = ReflectionUtils.invokeMethod(getPayload, message); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) ReflectionUtils .invokeMethod(getHeaders, message); headers = map; } else { payload = message; headers = Collections.emptyMap(); } return MessageBuilder.withPayload(payload).copyHeaders(headers).build(); }
Example 8
Source File: TilesConfigurer.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void registerRequestContextFactory(String className, List<TilesRequestContextFactory> factories, TilesRequestContextFactory parent) { // Avoid Tiles 2.2 warn logging when default RequestContextFactory impl class not found if (ClassUtils.isPresent(className, TilesConfigurer.class.getClassLoader())) { super.registerRequestContextFactory(className, factories, parent); } }
Example 9
Source File: DeferredResultMethodReturnValueHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public DeferredResultMethodReturnValueHandler() { this.adapterMap = new HashMap<Class<?>, DeferredResultAdapter>(5); this.adapterMap.put(DeferredResult.class, new SimpleDeferredResultAdapter()); this.adapterMap.put(ListenableFuture.class, new ListenableFutureAdapter()); if (ClassUtils.isPresent("java.util.concurrent.CompletionStage", getClass().getClassLoader())) { this.adapterMap.put(CompletionStage.class, new CompletionStageAdapter()); } }
Example 10
Source File: ConfigurationPropertiesJsr303Validator.java From spring-cloud-gray with Apache License 2.0 | 5 votes |
public static boolean isJsr303Present(ApplicationContext applicationContext) { ClassLoader classLoader = applicationContext.getClassLoader(); for (String validatorClass : VALIDATOR_CLASSES) { if (!ClassUtils.isPresent(validatorClass, classLoader)) { return false; } } return true; }
Example 11
Source File: TrimouTemplateAvailabilityProvider.java From trimou with Apache License 2.0 | 5 votes |
public boolean isTemplateAvailable(final String view, final Environment environment, final ClassLoader classLoader, final ResourceLoader resourceLoader) { if (ClassUtils.isPresent("org.trimou.Mustache", classLoader)) { final PropertyResolver resolver = new RelaxedPropertyResolver(environment, TrimouProperties.PROPERTY_PREFIX + '.'); final String prefix = resolver.getProperty("prefix", SpringResourceTemplateLocator.DEFAULT_PREFIX); final String suffix = resolver.getProperty("suffix", SpringResourceTemplateLocator.DEFAULT_SUFFIX); final String resourceLocation = prefix + view + suffix; return resourceLoader.getResource(resourceLocation).exists(); } return false; }
Example 12
Source File: FilterImportSelector.java From Milkomeda with MIT License | 4 votes |
@Override public String[] selectImports(AnnotationMetadata importingClassMetadata) { boolean tomcatPresent = ClassUtils.isPresent("org.apache.catalina.core.StandardContext", getClass().getClassLoader()); return tomcatPresent ? new String[] {"com.github.yizzuide.milkomeda.hydrogen.filter.TomcatFilterConfig"} : new String[] {}; }
Example 13
Source File: LocalSessionFactoryBuilder.java From java-technology-stack with MIT License | 4 votes |
/** * Set the Spring {@link JtaTransactionManager} or the JTA {@link TransactionManager} * to be used with Hibernate, if any. Allows for using a Spring-managed transaction * manager for Hibernate 5's session and cache synchronization, with the * "hibernate.transaction.jta.platform" automatically set to it. * <p>A passed-in Spring {@link JtaTransactionManager} needs to contain a JTA * {@link TransactionManager} reference to be usable here, except for the WebSphere * case where we'll automatically set {@code WebSphereExtendedJtaPlatform} accordingly. * <p>Note: If this is set, the Hibernate settings should not contain a JTA platform * setting to avoid meaningless double configuration. */ public LocalSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager) { Assert.notNull(jtaTransactionManager, "Transaction manager reference must not be null"); if (jtaTransactionManager instanceof JtaTransactionManager) { boolean webspherePresent = ClassUtils.isPresent("com.ibm.wsspi.uow.UOWManager", getClass().getClassLoader()); if (webspherePresent) { getProperties().put(AvailableSettings.JTA_PLATFORM, "org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform"); } else { JtaTransactionManager jtaTm = (JtaTransactionManager) jtaTransactionManager; if (jtaTm.getTransactionManager() == null) { throw new IllegalArgumentException( "Can only apply JtaTransactionManager which has a TransactionManager reference set"); } getProperties().put(AvailableSettings.JTA_PLATFORM, new ConfigurableJtaPlatform(jtaTm.getTransactionManager(), jtaTm.getUserTransaction(), jtaTm.getTransactionSynchronizationRegistry())); } } else if (jtaTransactionManager instanceof TransactionManager) { getProperties().put(AvailableSettings.JTA_PLATFORM, new ConfigurableJtaPlatform((TransactionManager) jtaTransactionManager, null, null)); } else { throw new IllegalArgumentException( "Unknown transaction manager type: " + jtaTransactionManager.getClass().getName()); } // Hibernate 5.1/5.2: manually enforce connection release mode AFTER_STATEMENT (the JTA default) try { // Try Hibernate 5.2 AvailableSettings.class.getField("CONNECTION_HANDLING"); getProperties().put("hibernate.connection.handling_mode", "DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT"); } catch (NoSuchFieldException ex) { // Try Hibernate 5.1 try { AvailableSettings.class.getField("ACQUIRE_CONNECTIONS"); getProperties().put("hibernate.connection.release_mode", "AFTER_STATEMENT"); } catch (NoSuchFieldException ex2) { // on Hibernate 5.0.x or lower - no need to change the default there } } return this; }
Example 14
Source File: Types.java From moduliths with Apache License 2.0 | 4 votes |
public static boolean isPresent() { return ClassUtils.isPresent(ENTITY_ANNOTATION, JDDDTypes.class.getClassLoader()); }
Example 15
Source File: ApiClientUtils.java From onetwo with Apache License 2.0 | 4 votes |
public static boolean isRequestMappingPresent(){ return ClassUtils.isPresent(CLASS_REQUEST_MAPPING, null); }
Example 16
Source File: TransactionManagementConfigurationSelector.java From spring-analysis-note with MIT License | 4 votes |
private String determineTransactionAspectClass() { return (ClassUtils.isPresent("javax.transaction.Transactional", getClass().getClassLoader()) ? TransactionManagementConfigUtils.JTA_TRANSACTION_ASPECT_CONFIGURATION_CLASS_NAME : TransactionManagementConfigUtils.TRANSACTION_ASPECT_CONFIGURATION_CLASS_NAME); }
Example 17
Source File: DubboServiceBeanMetadataResolver.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
private boolean isClassPresent(String className) { return ClassUtils.isPresent(className, classLoader); }
Example 18
Source File: FeignClientToDubboProviderBeanPostProcessor.java From spring-cloud-dubbo with Apache License 2.0 | 3 votes |
private Class<?> resolveServiceInterfaceClass(Class<?> annotatedServiceBeanClass, Service service) { Class<?> interfaceClass = service.interfaceClass(); if (void.class.equals(interfaceClass)) { interfaceClass = null; String interfaceClassName = service.interfaceName(); if (StringUtils.hasText(interfaceClassName)) { if (ClassUtils.isPresent(interfaceClassName, classLoader)) { interfaceClass = resolveClassName(interfaceClassName, classLoader); } } } if (interfaceClass == null) { Class<?>[] allInterfaces = annotatedServiceBeanClass.getInterfaces(); if (allInterfaces.length > 0) { interfaceClass = allInterfaces[0]; } } Assert.notNull(interfaceClass, "@Service interfaceClass() or interfaceName() or interface class must be present!"); Assert.isTrue(interfaceClass.isInterface(), "The type that was annotated @Service is not an interface!"); return interfaceClass; }
Example 19
Source File: ActorRepositoryIntegrationTest.java From spring-data-examples with Apache License 2.0 | 3 votes |
private static boolean fallBackToVersionSpecificClasses() { ClassLoader usedClassLoader = ActorRepositoryIntegrationTest.class.getClassLoader(); String fqnBoot210Class = "org.springframework.boot.autoconfigure.insight.InsightsProperties"; String fqnBoot205Class = "org.springframework.boot.autoconfigure.security.servlet.RequestMatcherProvider"; return ClassUtils.isPresent(fqnBoot210Class, usedClassLoader) // || ClassUtils.isPresent(fqnBoot205Class, usedClassLoader); }
Example 20
Source File: ReferenceBeanBuilder.java From dubbo-2.6.5 with Apache License 2.0 | 3 votes |
private void configureInterface(Reference reference, ReferenceBean referenceBean) { Class<?> interfaceClass = reference.interfaceClass(); if (void.class.equals(interfaceClass)) { interfaceClass = null; String interfaceClassName = reference.interfaceName(); if (StringUtils.hasText(interfaceClassName)) { if (ClassUtils.isPresent(interfaceClassName, classLoader)) { interfaceClass = ClassUtils.resolveClassName(interfaceClassName, classLoader); } } } if (interfaceClass == null) { interfaceClass = this.interfaceClass; } Assert.isTrue(interfaceClass.isInterface(), "The class of field or method that was annotated @Reference is not an interface!"); referenceBean.setInterface(interfaceClass); }