List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:org.springframework.boot.web.embedded.jetty.JettyWebServer.java
private void initialize() { synchronized (this.monitor) { try {/* www .j a v a 2 s. c o m*/ // Cache the connectors and then remove them to prevent requests being // handled before the application context is ready. this.connectors = this.server.getConnectors(); this.server.addBean(new AbstractLifeCycle() { @Override protected void doStart() throws Exception { for (Connector connector : JettyWebServer.this.connectors) { Assert.state(connector.isStopped(), () -> "Connector " + connector + " has been started prematurely"); } JettyWebServer.this.server.setConnectors(null); } }); // Start the server so that the ServletContext is available this.server.start(); this.server.setStopAtShutdown(false); } catch (Throwable ex) { // Ensure process isn't left running stopSilently(); throw new WebServerException("Unable to start embedded Jetty web server", ex); } } }
From source file:org.springframework.boot.web.servlet.support.SpringBootServletInitializer.java
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { SpringApplicationBuilder builder = createSpringApplicationBuilder(); builder.main(getClass());/* w w w .j a va 2s. c o m*/ ApplicationContext parent = getExistingRootWebApplicationContext(servletContext); if (parent != null) { this.logger.info("Root context already created (using as parent)."); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null); builder.initializers(new ParentContextApplicationContextInitializer(parent)); } builder.initializers(new ServletContextApplicationContextInitializer(servletContext)); builder.contextClass(AnnotationConfigServletWebServerApplicationContext.class); builder = configure(builder); builder.listeners(new WebEnvironmentPropertySourceInitializer(servletContext)); SpringApplication application = builder.build(); if (application.getAllSources().isEmpty() && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) { application.addPrimarySources(Collections.singleton(getClass())); } Assert.state(!application.getAllSources().isEmpty(), "No SpringApplication sources have been defined. Either override the " + "configure method or add an @Configuration annotation"); // Ensure error pages are registered if (this.registerErrorPageFilter) { application.addPrimarySources(Collections.singleton(ErrorPageFilterConfiguration.class)); } return run(application); }
From source file:org.springframework.boot.web.support.SpringBootServletInitializer.java
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { SpringApplicationBuilder builder = createSpringApplicationBuilder(); builder.main(getClass());/* w w w . j av a 2s. c o m*/ ApplicationContext parent = getExistingRootWebApplicationContext(servletContext); if (parent != null) { this.logger.info("Root context already created (using as parent)."); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null); builder.initializers(new ParentContextApplicationContextInitializer(parent)); } builder.initializers(new ServletContextApplicationContextInitializer(servletContext)); builder.listeners(new ServletContextApplicationListener(servletContext)); builder.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); builder = configure(builder); SpringApplication application = builder.build(); if (application.getSources().isEmpty() && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) { application.getSources().add(getClass()); } Assert.state(!application.getSources().isEmpty(), "No SpringApplication sources have been defined. Either override the " + "configure method or add an @Configuration annotation"); // Ensure error pages are registered if (this.registerErrorPageFilter) { application.getSources().add(ErrorPageFilterConfiguration.class); } return run(application); }
From source file:org.springframework.bus.runner.config.MessageBusProperties.java
private boolean isTap() { if (tap != null) { Assert.state(tap.getName() != null, "Tap name not provided"); Assert.state(!tap.getGroup().equals(group), "Tap group cannot be the same as module group"); }//from w w w. ja va 2s. c om return tap != null; }
From source file:org.springframework.cache.interceptor.CacheAspectSupport.java
@Override public void afterPropertiesSet() { Assert.state(getCacheOperationSource() != null, "The 'cacheOperationSources' property is required: " + "If there are no cacheable methods, then don't use a cache aspect."); }
From source file:org.springframework.cache.interceptor.CacheAspectSupport.java
@Override public void afterSingletonsInstantiated() { if (getCacheResolver() == null) { // Lazily initialize cache resolver via default cache manager... Assert.state(this.beanFactory != null, "CacheResolver or BeanFactory must be set on cache aspect"); try {//from ww w . j av a2 s .co m setCacheManager(this.beanFactory.getBean(CacheManager.class)); } catch (NoUniqueBeanDefinitionException ex) { throw new IllegalStateException("No CacheResolver specified, and no unique bean of type " + "CacheManager found. Mark one as primary (or give it the name 'cacheManager') or " + "declare a specific CacheManager to use, that serves as the default one."); } catch (NoSuchBeanDefinitionException ex) { throw new IllegalStateException( "No CacheResolver specified, and no bean of type CacheManager found. " + "Register a CacheManager bean or remove the @EnableCaching annotation from your configuration."); } } this.initialized = true; }
From source file:org.springframework.cache.interceptor.CacheAspectSupport.java
/** * Return the {@link CacheOperationMetadata} for the specified operation. * <p>Resolve the {@link CacheResolver} and the {@link KeyGenerator} to be * used for the operation.// ww w . j ava2s.c om * @param operation the operation * @param method the method on which the operation is invoked * @param targetClass the target type * @return the resolved metadata for the operation */ protected CacheOperationMetadata getCacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass) { CacheOperationCacheKey cacheKey = new CacheOperationCacheKey(operation, method, targetClass); CacheOperationMetadata metadata = this.metadataCache.get(cacheKey); if (metadata == null) { KeyGenerator operationKeyGenerator; if (StringUtils.hasText(operation.getKeyGenerator())) { operationKeyGenerator = getBean(operation.getKeyGenerator(), KeyGenerator.class); } else { operationKeyGenerator = getKeyGenerator(); } CacheResolver operationCacheResolver; if (StringUtils.hasText(operation.getCacheResolver())) { operationCacheResolver = getBean(operation.getCacheResolver(), CacheResolver.class); } else if (StringUtils.hasText(operation.getCacheManager())) { CacheManager cacheManager = getBean(operation.getCacheManager(), CacheManager.class); operationCacheResolver = new SimpleCacheResolver(cacheManager); } else { operationCacheResolver = getCacheResolver(); Assert.state(operationCacheResolver != null, "No CacheResolver/CacheManager set"); } metadata = new CacheOperationMetadata(operation, method, targetClass, operationKeyGenerator, operationCacheResolver); this.metadataCache.put(cacheKey, metadata); } return metadata; }
From source file:org.springframework.cache.jcache.interceptor.JCacheAspectSupport.java
public void afterPropertiesSet() { Assert.state(getCacheOperationSource() != null, "The 'cacheOperationSource' property is required: " + "If there are no cacheable methods, then don't use a cache aspect."); this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler()); this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler()); this.cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(getErrorHandler()); this.cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(getErrorHandler()); this.initialized = true; }
From source file:org.springframework.cloud.config.server.environment.SvnKitEnvironmentRepository.java
@Override public void afterPropertiesSet() throws Exception { Assert.state(getUri() != null, "You need to configure a uri for the subversion repository (e.g. 'http://example.com/svn/')"); resolveRelativeFileUri();/*w ww.j a v a2 s. c o m*/ }
From source file:org.springframework.cloud.config.server.JGitEnvironmentRepository.java
private Git copyRepository() throws IOException, GitAPIException { deleteBaseDirIfExists();/*w ww . ja va 2 s. co m*/ Assert.state(basedir.mkdirs(), "Could not create basedir: " + basedir); if (uri.startsWith("file:")) { return copyFromLocalRepository(); } else { return cloneToBasedir(); } }