在本文中,我们将带你了解configuration虚拟主机和本地主机redirect到xampp文件夹在这篇文章中,我们将为您详细介绍configuration虚拟主机和本地主机redirect到xa
在本文中,我们将带你了解configuration虚拟主机和本地主机redirect到xampp文件夹在这篇文章中,我们将为您详细介绍configuration虚拟主机和本地主机redirect到xampp文件夹的方方面面,并解答xampp配置虚拟主机常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的006-spring cache-缓存原理-SimpleCacheConfiguration、RedisCacheConfiguration原理实现、: No JAAS configuration section named ''Client'' was found in specified JAAS configuration file:、@Configuration @AutoConfigureAfter @Autowired、apache configuration directives。
本文目录一览:- configuration虚拟主机和本地主机redirect到xampp文件夹(xampp配置虚拟主机)
- 006-spring cache-缓存原理-SimpleCacheConfiguration、RedisCacheConfiguration原理实现
- : No JAAS configuration section named ''Client'' was found in specified JAAS configuration file:
- @Configuration @AutoConfigureAfter @Autowired
- apache configuration directives
configuration虚拟主机和本地主机redirect到xampp文件夹(xampp配置虚拟主机)
我有创build虚拟主机的问题。 我正在使用Windows 7 x64专业版。 在文件C:WindowsSystem32driversetchosts我只有这样的行:
127.0.0.1 myhost 127.0.0.1 www.myhost
并在文件C:xamppapacheconfextrahttpd-vhosts.conf我有这样的:
NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/" ServerName localhost ServerAlias www.localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/Users/Me/DropBox/Project/public" ServerName myhost ServerAlias www.myhost <Directory "C:/Users/Me/DropBox/Project/public"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
当然,在这些文件中添加这些行后,我已经恢复了我的Apache服务器。 不幸在我的浏览器中inputmyhost或www.myhost会将我redirect到myhost/xampp 。
我已经search,我已经find谷歌和也stackoverflow描述如何configuration虚拟主机使用xampp,但我怎么能认识到我做了一切正常。 我知道我的问题不是新的,但我没有find工作的解决scheme。
Nginx – 我可以添加一个新的虚拟主机,而无需重新启动服务器?
Apache默认的VirtualHost
不同的VirtualHosts具有相同的端口
在启动基于定制的Amazon Linux AMI的ec2后,第二个虚拟主机的DocumentRoot被更改
错误28105#0:* 1在读取来自上游的响应头时,在stderr中发送了FastCGI:“主脚本未知”
我也认识到,在我的浏览器中键入localhostredirect我localhost/xampp 。 我不知道这些问题是否与我的情况有关。
Apache的多个虚拟主机在相同的IP(不同的url)
虚拟子域:每个用户一个子域
Apache httpd.conf用于将IPredirect到主机名
使用Nginx使用phusion乘客3.0.17运行多个rails网站
WAMP服务器虚拟主机configuration
我有同样的问题。 您的第一个请求是重定向到htdocs根目录。 如果您查看htdocs目录中的index.PHP,您可以看到非常简短的代码,它将传入的请求重定向到xampp目录。
我通过摆弄httpd-vhosts.conf文件来修复它。 在你的情况下,请尝试进行以下编辑:
NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1> DocumentRoot "C:xampphtdocs serverName localhost </VirtualHost> <VirtualHost www.myhost> DocumentRoot "C:UsersMeDropBoxProjectpublic" serverName www.myhost serverAlias www.myhost <Directory "C:UsersMeDropBoxProjectpublic"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
我有一个类似的问题,发现我不得不去我的Apache24主要的httpd.conf文件,取消围绕行501“包括conf / extra / httpd-vhost.conf”我以前从来没有使用过,它仍然#''ed出。 希望这有助于没有在这里找到其他答案的人。 我的Apache24现在可以看到我的虚拟主机文件。
您需要启用基于名称的虚拟主机。
在C: xampp apache conf extra httpd-vhosts中靠近文件顶部
取消注释#Name虚拟主机*:80
即来自:
# # Use name-based virtual hosting. # #NameVirtualHost *:80
至:
# # Use name-based virtual hosting. # NameVirtualHost *:80
(注意现在的最后一行是未注释的)。
为我工作就像一个魅力。
总结
以上是小编为你收集整理的configuration虚拟主机和本地主机redirect到xampp文件夹全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
006-spring cache-缓存原理-SimpleCacheConfiguration、RedisCacheConfiguration原理实现
一、实现说明
事务回滚:除了GuavaCacheManager之外,其他Cache都支持Spring事务,即如果事务回滚了,缓存的数据也会移除掉。
Spring不进行cache的定义,也不进行Cache的缓存策略的维护。这些都是由底层cache自己实现,然后外部创建一个cache注入进来的。Spring只是提供了一个Wrapper,提供一套对外一致的API。
CacheManger | 描述 |
---|---|
SimpleCacheManager | 使用简单的Collection来存储缓存,主要用于测试 |
ConcurrentMapCacheManager | 使用ConcurrentMap作为缓存技术(默认) |
NoOpCacheManager | 测试用 |
EhCacheCacheManager | 使用EhCache作为缓存技术,以前在hibernate的时候经常用 |
GuavaCacheManager | 使用google guava的GuavaCache作为缓存技术 |
HazelcastCacheManager | 使用Hazelcast作为缓存技术 |
JCacheCacheManager | 使用JCache标准的实现作为缓存技术,如Apache Commons JCS |
RedisCacheManager | 使用Redis作为缓存技术 |
springboot cache
static {
Map<CacheType, Class<?>> mappings = new EnumMap<>(CacheType.class);
mappings.put(CacheType.GENERIC, GenericCacheConfiguration.class);
mappings.put(CacheType.EHCACHE, EhCacheCacheConfiguration.class);
mappings.put(CacheType.HAZELCAST, HazelcastCacheConfiguration.class);
mappings.put(CacheType.INFINISPAN, InfinispanCacheConfiguration.class);
mappings.put(CacheType.JCACHE, JCacheCacheConfiguration.class);
mappings.put(CacheType.COUCHBASE, CouchbaseCacheConfiguration.class);
mappings.put(CacheType.REDIS, RedisCacheConfiguration.class);
mappings.put(CacheType.CAFFEINE, CaffeineCacheConfiguration.class);
mappings.put(CacheType.SIMPLE, SimpleCacheConfiguration.class);
mappings.put(CacheType.NONE, NoOpCacheConfiguration.class);
MAPPINGS = Collections.unmodifiableMap(mappings);
}
Spring boot默认使用的是SimpleCacheConfiguration,即使用ConcurrentMapCacheManager来实现缓存。
二、CacheManager说明
2.1、SimpleCacheConfiguration 说明
核心UML图
查看ConcurrentMapCache实现 核心是ValueWrapper
2.1.1、SimpleCacheConfiguration说明实现
代码地址:https://github.com/bjlhx15/common.git spring-cache/springboot2-cache-default
2.1.2、基础配置
参看:001-spring cache 简介、基础使用
2.2、RedisCacheConfiguration说明
1、RedisCacheConfiguration
配置类配置缓存管理器


/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.cache;
import java.util.LinkedHashSet;
import java.util.List;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.cache.CacheProperties.Redis;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheManager.RedisCacheManagerBuilder;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
/**
* Redis cache configuration.
*
* @author Stephane Nicoll
* @author Mark Paluch
* @author Ryon Day
* @since 1.3.0
*/
@Configuration
@ConditionalOnClass(RedisConnectionFactory.class)
@AutoConfigureAfter(RedisAutoConfiguration.class)
@ConditionalOnBean(RedisConnectionFactory.class)
@ConditionalOnMissingBean(CacheManager.class)
@Conditional(CacheCondition.class)
class RedisCacheConfiguration {
private final CacheProperties cacheProperties;
private final CacheManagerCustomizers customizerInvoker;
private final org.springframework.data.redis.cache.RedisCacheConfiguration redisCacheConfiguration;
RedisCacheConfiguration(CacheProperties cacheProperties,
CacheManagerCustomizers customizerInvoker,
ObjectProvider<org.springframework.data.redis.cache.RedisCacheConfiguration> redisCacheConfiguration) {
this.cacheProperties = cacheProperties;
this.customizerInvoker = customizerInvoker;
this.redisCacheConfiguration = redisCacheConfiguration.getIfAvailable();
}
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory,
ResourceLoader resourceLoader) {
RedisCacheManagerBuilder builder = RedisCacheManager
.builder(redisConnectionFactory)
.cacheDefaults(determineConfiguration(resourceLoader.getClassLoader()));
List<String> cacheNames = this.cacheProperties.getCacheNames();
if (!cacheNames.isEmpty()) {
builder.initialCacheNames(new LinkedHashSet<>(cacheNames));
}
return this.customizerInvoker.customize(builder.build());
}
private org.springframework.data.redis.cache.RedisCacheConfiguration determineConfiguration(
ClassLoader classLoader) {
if (this.redisCacheConfiguration != null) {
return this.redisCacheConfiguration;
}
Redis redisProperties = this.cacheProperties.getRedis();
org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration
.defaultCacheConfig();
config = config.serializeValuesWith(SerializationPair
.fromSerializer(new JdkSerializationRedisSerializer(classLoader)));
if (redisProperties.getTimeToLive() != null) {
config = config.entryTtl(redisProperties.getTimeToLive());
}
if (redisProperties.getKeyPrefix() != null) {
config = config.prefixKeysWith(redisProperties.getKeyPrefix());
}
if (!redisProperties.isCacheNullValues()) {
config = config.disableCachingNullValues();
}
if (!redisProperties.isUseKeyPrefix()) {
config = config.disableKeyPrefix();
}
return config;
}
}
注入方法
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory,
ResourceLoader resourceLoader) {
RedisCacheManagerBuilder builder = RedisCacheManager
.builder(redisConnectionFactory)
.cacheDefaults(determineConfiguration(resourceLoader.getClassLoader()));
List<String> cacheNames = this.cacheProperties.getCacheNames();
if (!cacheNames.isEmpty()) {
builder.initialCacheNames(new LinkedHashSet<>(cacheNames));
}
return this.customizerInvoker.customize(builder.build());
}
可以看到 核心是 创建了一个 RedisCacheManager,同时使用:initialCacheNames(new LinkedHashSet<>(cacheNames));
2、RedisCacheManager
继承关系:RedisCacheManager→AbstractTransactionSupportingCacheManager【事务支持抽象类】→ AbstractCacheManager→CacheManager、InitializingBean
CacheManager:提供原始管理接口方法
InitializingBean:主要作用是Bean初始化后执行一个afterPropertiesSet方法 003-Spring4 扩展分析-spring类初始化@PostConstruct > InitializingBean > init-method、ApplicationContext、BeanPostProcessor、BeanFactoryPostProcessor、BeanDefinitionRegistryPostProcessor
AbstractCacheManager:afterPropertiesSet中调用 initializeCaches
public void initializeCaches() {
Collection<? extends Cache> caches = loadCaches();
synchronized (this.cacheMap) {
this.cacheNames = Collections.emptySet();
this.cacheMap.clear();
Set<String> cacheNames = new LinkedHashSet<>(caches.size());
for (Cache cache : caches) {
String name = cache.getName();
this.cacheMap.put(name, decorateCache(cache));
cacheNames.add(name);
}
this.cacheNames = Collections.unmodifiableSet(cacheNames);
}
}
其一调用了:loadCaches;其二 初始化缓存名
RedisCacheManager主要管理缓存


/*
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.cache;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* {@link org.springframework.cache.CacheManager} backed by a {@link RedisCache Redis} cache.
* <p />
* This cache manager creates caches by default upon first write. Empty caches are not visible on Redis due to how Redis
* represents empty data structures.
* <p />
* Caches requiring a different {@link RedisCacheConfiguration} than the default configuration can be specified via
* {@link RedisCacheManagerBuilder#withInitialCacheConfigurations(Map)}.
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
* @see RedisCacheConfiguration
* @see RedisCacheWriter
*/
public class RedisCacheManager extends AbstractTransactionSupportingCacheManager {
private final RedisCacheWriter cacheWriter;
private final RedisCacheConfiguration defaultCacheConfig;
private final Map<String, RedisCacheConfiguration> initialCacheConfiguration;
private final boolean allowInFlightCacheCreation;
/**
* Creates new {@link RedisCacheManager} using given {@link RedisCacheWriter} and default
* {@link RedisCacheConfiguration}.
*
* @param cacheWriter must not be {@literal null}.
* @param defaultCacheConfiguration must not be {@literal null}. Maybe just use
* {@link RedisCacheConfiguration#defaultCacheConfig()}.
* @param allowInFlightCacheCreation allow create unconfigured caches.
* @since 2.0.4
*/
private RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
boolean allowInFlightCacheCreation) {
Assert.notNull(cacheWriter, "CacheWriter must not be null!");
Assert.notNull(defaultCacheConfiguration, "DefaultCacheConfiguration must not be null!");
this.cacheWriter = cacheWriter;
this.defaultCacheConfig = defaultCacheConfiguration;
this.initialCacheConfiguration = new LinkedHashMap<>();
this.allowInFlightCacheCreation = allowInFlightCacheCreation;
}
/**
* Creates new {@link RedisCacheManager} using given {@link RedisCacheWriter} and default
* {@link RedisCacheConfiguration}.
*
* @param cacheWriter must not be {@literal null}.
* @param defaultCacheConfiguration must not be {@literal null}. Maybe just use
* {@link RedisCacheConfiguration#defaultCacheConfig()}.
*/
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {
this(cacheWriter, defaultCacheConfiguration, true);
}
/**
* Creates new {@link RedisCacheManager} using given {@link RedisCacheWriter} and default
* {@link RedisCacheConfiguration}.
*
* @param cacheWriter must not be {@literal null}.
* @param defaultCacheConfiguration must not be {@literal null}. Maybe just use
* {@link RedisCacheConfiguration#defaultCacheConfig()}.
* @param initialCacheNames optional set of known cache names that will be created with given
* {@literal defaultCacheConfiguration}.
*/
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
String... initialCacheNames) {
this(cacheWriter, defaultCacheConfiguration, true, initialCacheNames);
}
/**
* Creates new {@link RedisCacheManager} using given {@link RedisCacheWriter} and default
* {@link RedisCacheConfiguration}.
*
* @param cacheWriter must not be {@literal null}.
* @param defaultCacheConfiguration must not be {@literal null}. Maybe just use
* {@link RedisCacheConfiguration#defaultCacheConfig()}.
* @param allowInFlightCacheCreation if set to {@literal true} no new caches can be acquire at runtime but limited to
* the given list of initial cache names.
* @param initialCacheNames optional set of known cache names that will be created with given
* {@literal defaultCacheConfiguration}.
* @since 2.0.4
*/
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
boolean allowInFlightCacheCreation, String... initialCacheNames) {
this(cacheWriter, defaultCacheConfiguration, allowInFlightCacheCreation);
for (String cacheName : initialCacheNames) {
this.initialCacheConfiguration.put(cacheName, defaultCacheConfiguration);
}
}
/**
* Creates new {@link RedisCacheManager} using given {@link RedisCacheWriter} and default
* {@link RedisCacheConfiguration}.
*
* @param cacheWriter must not be {@literal null}.
* @param defaultCacheConfiguration must not be {@literal null}. Maybe just use
* {@link RedisCacheConfiguration#defaultCacheConfig()}.
* @param initialCacheConfigurations Map of known cache names along with the configuration to use for those caches.
* Must not be {@literal null}.
*/
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
Map<String, RedisCacheConfiguration> initialCacheConfigurations) {
this(cacheWriter, defaultCacheConfiguration, initialCacheConfigurations, true);
}
/**
* Creates new {@link RedisCacheManager} using given {@link RedisCacheWriter} and default
* {@link RedisCacheConfiguration}.
*
* @param cacheWriter must not be {@literal null}.
* @param defaultCacheConfiguration must not be {@literal null}. Maybe just use
* {@link RedisCacheConfiguration#defaultCacheConfig()}.
* @param initialCacheConfigurations Map of known cache names along with the configuration to use for those caches.
* Must not be {@literal null}.
* @param allowInFlightCacheCreation if set to {@literal false} this cache manager is limited to the initial cache
* configurations and will not create new caches at runtime.
* @since 2.0.4
*/
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) {
this(cacheWriter, defaultCacheConfiguration, allowInFlightCacheCreation);
Assert.notNull(initialCacheConfigurations, "InitialCacheConfigurations must not be null!");
this.initialCacheConfiguration.putAll(initialCacheConfigurations);
}
/**
* Create a new {@link RedisCacheManager} with defaults applied.
* <dl>
* <dt>locking</dt>
* <dd>disabled</dd>
* <dt>cache configuration</dt>
* <dd>{@link RedisCacheConfiguration#defaultCacheConfig()}</dd>
* <dt>initial caches</dt>
* <dd>none</dd>
* <dt>transaction aware</dt>
* <dd>no</dd>
* <dt>in-flight cache creation</dt>
* <dd>enabled</dd>
* </dl>
*
* @param connectionFactory must not be {@literal null}.
* @return new instance of {@link RedisCacheManager}.
*/
public static RedisCacheManager create(RedisConnectionFactory connectionFactory) {
Assert.notNull(connectionFactory, "ConnectionFactory must not be null!");
return new RedisCacheManager(new DefaultRedisCacheWriter(connectionFactory),
RedisCacheConfiguration.defaultCacheConfig());
}
/**
* Entry point for builder style {@link RedisCacheManager} configuration.
*
* @param connectionFactory must not be {@literal null}.
* @return new {@link RedisCacheManagerBuilder}.
*/
public static RedisCacheManagerBuilder builder(RedisConnectionFactory connectionFactory) {
Assert.notNull(connectionFactory, "ConnectionFactory must not be null!");
return RedisCacheManagerBuilder.fromConnectionFactory(connectionFactory);
}
/**
* Entry point for builder style {@link RedisCacheManager} configuration.
*
* @param cacheWriter must not be {@literal null}.
* @return new {@link RedisCacheManagerBuilder}.
*/
public static RedisCacheManagerBuilder builder(RedisCacheWriter cacheWriter) {
Assert.notNull(cacheWriter, "CacheWriter must not be null!");
return RedisCacheManagerBuilder.fromCacheWriter(cacheWriter);
}
/*
* (non-Javadoc)
* @see org.springframework.cache.support.AbstractCacheManager#loadCaches()
*/
@Override
protected Collection<RedisCache> loadCaches() {
List<RedisCache> caches = new LinkedList<>();
for (Map.Entry<String, RedisCacheConfiguration> entry : initialCacheConfiguration.entrySet()) {
caches.add(createRedisCache(entry.getKey(), entry.getValue()));
}
return caches;
}
/*
* (non-Javadoc)
* @see org.springframework.cache.support.AbstractCacheManager#getMissingCache(java.lang.String)
*/
@Override
protected RedisCache getMissingCache(String name) {
return allowInFlightCacheCreation ? createRedisCache(name, defaultCacheConfig) : null;
}
/**
* @return unmodifiable {@link Map} containing cache name / configuration pairs. Never {@literal null}.
*/
public Map<String, RedisCacheConfiguration> getCacheConfigurations() {
Map<String, RedisCacheConfiguration> configurationMap = new HashMap<>(getCacheNames().size());
getCacheNames().forEach(it -> {
RedisCache cache = RedisCache.class.cast(lookupCache(it));
configurationMap.put(it, cache != null ? cache.getCacheConfiguration() : null);
});
return Collections.unmodifiableMap(configurationMap);
}
/**
* Configuration hook for creating {@link RedisCache} with given name and {@code cacheConfig}.
*
* @param name must not be {@literal null}.
* @param cacheConfig can be {@literal null}.
* @return never {@literal null}.
*/
protected RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfig) {
return new RedisCache(name, cacheWriter, cacheConfig != null ? cacheConfig : defaultCacheConfig);
}
/**
* Configurator for creating {@link RedisCacheManager}.
*
* @author Christoph Strobl
* @author Mark Strobl
* @author Kezhu Wang
* @since 2.0
*/
public static class RedisCacheManagerBuilder {
private final RedisCacheWriter cacheWriter;
private RedisCacheConfiguration defaultCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
private final Map<String, RedisCacheConfiguration> initialCaches = new LinkedHashMap<>();
private boolean enableTransactions;
boolean allowInFlightCacheCreation = true;
private RedisCacheManagerBuilder(RedisCacheWriter cacheWriter) {
this.cacheWriter = cacheWriter;
}
/**
* Entry point for builder style {@link RedisCacheManager} configuration.
*
* @param connectionFactory must not be {@literal null}.
* @return new {@link RedisCacheManagerBuilder}.
*/
public static RedisCacheManagerBuilder fromConnectionFactory(RedisConnectionFactory connectionFactory) {
Assert.notNull(connectionFactory, "ConnectionFactory must not be null!");
return builder(new DefaultRedisCacheWriter(connectionFactory));
}
/**
* Entry point for builder style {@link RedisCacheManager} configuration.
*
* @param cacheWriter must not be {@literal null}.
* @return new {@link RedisCacheManagerBuilder}.
*/
public static RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWriter) {
Assert.notNull(cacheWriter, "CacheWriter must not be null!");
return new RedisCacheManagerBuilder(cacheWriter);
}
/**
* Define a default {@link RedisCacheConfiguration} applied to dynamically created {@link RedisCache}s.
*
* @param defaultCacheConfiguration must not be {@literal null}.
* @return this {@link RedisCacheManagerBuilder}.
*/
public RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCacheConfiguration) {
Assert.notNull(defaultCacheConfiguration, "DefaultCacheConfiguration must not be null!");
this.defaultCacheConfiguration = defaultCacheConfiguration;
return this;
}
/**
* Enable {@link RedisCache}s to synchronize cache put/evict operations with ongoing Spring-managed transactions.
*
* @return this {@link RedisCacheManagerBuilder}.
*/
public RedisCacheManagerBuilder transactionAware() {
this.enableTransactions = true;
return this;
}
/**
* Append a {@link Set} of cache names to be pre initialized with current {@link RedisCacheConfiguration}.
* <strong>NOTE:</strong> This calls depends on {@link #cacheDefaults(RedisCacheConfiguration)} using whatever
* default {@link RedisCacheConfiguration} is present at the time of invoking this method.
*
* @param cacheNames must not be {@literal null}.
* @return this {@link RedisCacheManagerBuilder}.
*/
public RedisCacheManagerBuilder initialCacheNames(Set<String> cacheNames) {
Assert.notNull(cacheNames, "CacheNames must not be null!");
Map<String, RedisCacheConfiguration> cacheConfigMap = new LinkedHashMap<>(cacheNames.size());
cacheNames.forEach(it -> cacheConfigMap.put(it, defaultCacheConfiguration));
return withInitialCacheConfigurations(cacheConfigMap);
}
/**
* Append a {@link Map} of cache name/{@link RedisCacheConfiguration} pairs to be pre initialized.
*
* @param cacheConfigurations must not be {@literal null}.
* @return this {@link RedisCacheManagerBuilder}.
*/
public RedisCacheManagerBuilder withInitialCacheConfigurations(
Map<String, RedisCacheConfiguration> cacheConfigurations) {
Assert.notNull(cacheConfigurations, "CacheConfigurations must not be null!");
cacheConfigurations.forEach((cacheName, configuration) -> Assert.notNull(configuration,
String.format("RedisCacheConfiguration for cache %s must not be null!", cacheName)));
this.initialCaches.putAll(cacheConfigurations);
return this;
}
/**
* Disable in-flight {@link org.springframework.cache.Cache} creation for unconfigured caches.
* <p />
* {@link RedisCacheManager#getMissingCache(String)} returns {@literal null} for any unconfigured
* {@link org.springframework.cache.Cache} instead of a new {@link RedisCache} instance. This allows eg.
* {@link org.springframework.cache.support.CompositeCacheManager} to chime in.
*
* @return this {@link RedisCacheManagerBuilder}.
* @since 2.0.4
*/
public RedisCacheManagerBuilder disableCreateOnMissingCache() {
this.allowInFlightCacheCreation = false;
return this;
}
/**
* Create new instance of {@link RedisCacheManager} with configuration options applied.
*
* @return new instance of {@link RedisCacheManager}.
*/
public RedisCacheManager build() {
RedisCacheManager cm = new RedisCacheManager(cacheWriter, defaultCacheConfiguration, initialCaches,
allowInFlightCacheCreation);
cm.setTransactionAware(enableTransactions);
return cm;
}
}
}
这里使用了建造者模式:002-创建型-04-建造者模式(Builder)、JDK1.7源码中的建造者模式、Spring中的建造者模式
这里重写了:Collection<RedisCache> loadCaches()
@Override
protected Collection<RedisCache> loadCaches() {
List<RedisCache> caches = new LinkedList<>();
for (Map.Entry<String, RedisCacheConfiguration> entry : initialCacheConfiguration.entrySet()) {
caches.add(createRedisCache(entry.getKey(), entry.getValue()));
}
return caches;
}
所以在Bean初始化后会加载 RedisCache
3、RedisCache
直接看代码


/*
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.cache;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.concurrent.Callable;
import org.springframework.cache.support.AbstractValueAdaptingCache;
import org.springframework.cache.support.NullValue;
import org.springframework.cache.support.SimpleValueWrapper;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
/**
* {@link org.springframework.cache.Cache} implementation using for Redis as underlying store.
* <p />
* Use {@link RedisCacheManager} to create {@link RedisCache} instances.
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
* @see RedisCacheConfiguration
* @see RedisCacheWriter
*/
public class RedisCache extends AbstractValueAdaptingCache {
private static final byte[] BINARY_NULL_VALUE = new JdkSerializationRedisSerializer().serialize(NullValue.INSTANCE);
private final String name;
private final RedisCacheWriter cacheWriter;
private final RedisCacheConfiguration cacheConfig;
private final ConversionService conversionService;
/**
* Create new {@link RedisCache}.
*
* @param name must not be {@literal null}.
* @param cacheWriter must not be {@literal null}.
* @param cacheConfig must not be {@literal null}.
*/
protected RedisCache(String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) {
super(cacheConfig.getAllowCacheNullValues());
Assert.notNull(name, "Name must not be null!");
Assert.notNull(cacheWriter, "CacheWriter must not be null!");
Assert.notNull(cacheConfig, "CacheConfig must not be null!");
this.name = name;
this.cacheWriter = cacheWriter;
this.cacheConfig = cacheConfig;
this.conversionService = cacheConfig.getConversionService();
}
/*
* (non-Javadoc)
* @see org.springframework.cache.support.AbstractValueAdaptingCache#lookup(java.lang.Object)
*/
@Override
protected Object lookup(Object key) {
byte[] value = cacheWriter.get(name, createAndConvertCacheKey(key));
if (value == null) {
return null;
}
return deserializeCacheValue(value);
}
/*
* (non-Javadoc)
* @see org.springframework.cache.Cache#getName()
*/
@Override
public String getName() {
return name;
}
/*
* (non-Javadoc)
* @see org.springframework.cache.Cache#getNativeCache()
*/
@Override
public RedisCacheWriter getNativeCache() {
return this.cacheWriter;
}
/*
* (non-Javadoc)
* @see org.springframework.cache.Cache#get(java.lang.Object, java.util.concurrent.Callable)
*/
@Override
@SuppressWarnings("unchecked")
public synchronized <T> T get(Object key, Callable<T> valueLoader) {
ValueWrapper result = get(key);
if (result != null) {
return (T) result.get();
}
T value = valueFromLoader(key, valueLoader);
put(key, value);
return value;
}
/*
* (non-Javadoc)
* @see org.springframework.cache.Cache#put(java.lang.Object, java.lang.Object)
*/
@Override
public void put(Object key, @Nullable Object value) {
Object cacheValue = preProcessCacheValue(value);
if (!isAllowNullValues() && cacheValue == null) {
throw new IllegalArgumentException(String.format(
"Cache ''%s'' does not allow ''null'' values. Avoid storing null via ''@Cacheable(unless=\"#result == null\")'' or configure RedisCache to allow ''null'' via RedisCacheConfiguration.",
name));
}
cacheWriter.put(name, createAndConvertCacheKey(key), serializeCacheValue(cacheValue), cacheConfig.getTtl());
}
/*
* (non-Javadoc)
* @see org.springframework.cache.Cache#putIfAbsent(java.lang.Object, java.lang.Object)
*/
@Override
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
Object cacheValue = preProcessCacheValue(value);
if (!isAllowNullValues() && cacheValue == null) {
return get(key);
}
byte[] result = cacheWriter.putIfAbsent(name, createAndConvertCacheKey(key), serializeCacheValue(cacheValue),
cacheConfig.getTtl());
if (result == null) {
return null;
}
return new SimpleValueWrapper(fromStoreValue(deserializeCacheValue(result)));
}
/*
* (non-Javadoc)
* @see org.springframework.cache.Cache#evict(java.lang.Object)
*/
@Override
public void evict(Object key) {
cacheWriter.remove(name, createAndConvertCacheKey(key));
}
/*
* (non-Javadoc)
* @see org.springframework.cache.Cache#clear()
*/
@Override
public void clear() {
byte[] pattern = conversionService.convert(createCacheKey("*"), byte[].class);
cacheWriter.clean(name, pattern);
}
/**
* Get {@link RedisCacheConfiguration} used.
*
* @return immutable {@link RedisCacheConfiguration}. Never {@literal null}.
*/
public RedisCacheConfiguration getCacheConfiguration() {
return cacheConfig;
}
/**
* Customization hook called before passing object to
* {@link org.springframework.data.redis.serializer.RedisSerializer}.
*
* @param value can be {@literal null}.
* @return preprocessed value. Can be {@literal null}.
*/
@Nullable
protected Object preProcessCacheValue(@Nullable Object value) {
if (value != null) {
return value;
}
return isAllowNullValues() ? NullValue.INSTANCE : null;
}
/**
* Serialize the key.
*
* @param cacheKey must not be {@literal null}.
* @return never {@literal null}.
*/
protected byte[] serializeCacheKey(String cacheKey) {
return ByteUtils.getBytes(cacheConfig.getKeySerializationPair().write(cacheKey));
}
/**
* Serialize the value to cache.
*
* @param value must not be {@literal null}.
* @return never {@literal null}.
*/
protected byte[] serializeCacheValue(Object value) {
if (isAllowNullValues() && value instanceof NullValue) {
return BINARY_NULL_VALUE;
}
return ByteUtils.getBytes(cacheConfig.getValueSerializationPair().write(value));
}
/**
* Deserialize the given value to the actual cache value.
*
* @param value must not be {@literal null}.
* @return can be {@literal null}.
*/
@Nullable
protected Object deserializeCacheValue(byte[] value) {
if (isAllowNullValues() && ObjectUtils.nullSafeEquals(value, BINARY_NULL_VALUE)) {
return NullValue.INSTANCE;
}
return cacheConfig.getValueSerializationPair().read(ByteBuffer.wrap(value));
}
/**
* Customization hook for creating cache key before it gets serialized.
*
* @param key will never be {@literal null}.
* @return never {@literal null}.
*/
protected String createCacheKey(Object key) {
String convertedKey = convertKey(key);
if (!cacheConfig.usePrefix()) {
return convertedKey;
}
return prefixCacheKey(convertedKey);
}
/**
* Convert {@code key} to a {@link String} representation used for cache key creation.
*
* @param key will never be {@literal null}.
* @return never {@literal null}.
* @throws IllegalStateException if {@code key} cannot be converted to {@link String}.
*/
protected String convertKey(Object key) {
TypeDescriptor source = TypeDescriptor.forObject(key);
if (conversionService.canConvert(source, TypeDescriptor.valueOf(String.class))) {
return conversionService.convert(key, String.class);
}
Method toString = ReflectionUtils.findMethod(key.getClass(), "toString");
if (toString != null && !Object.class.equals(toString.getDeclaringClass())) {
return key.toString();
}
throw new IllegalStateException(
String.format("Cannot convert %s to String. Register a Converter or override toString().", source));
}
private byte[] createAndConvertCacheKey(Object key) {
return serializeCacheKey(createCacheKey(key));
}
private String prefixCacheKey(String key) {
// allow contextual cache names by computing the key prefix on every call.
return cacheConfig.getKeyPrefixFor(name) + key;
}
private static <T> T valueFromLoader(Object key, Callable<T> valueLoader) {
try {
return valueLoader.call();
} catch (Exception e) {
throw new ValueRetrievalException(key, valueLoader, e);
}
}
}
说明
private static final byte[] BINARY_NULL_VALUE = new JdkSerializationRedisSerializer().serialize(NullValue.INSTANCE);
private final String name; //缓存空间名
private final RedisCacheWriter cacheWriter; //redis操作对象
private final RedisCacheConfiguration cacheConfig; //缓存的配置 与springboot里面的不一样
private final ConversionService conversionService;
1、lookup(Object key) 取值
为了父类的 :ValueWrapper get(Object key); 以及<T> T get(Object key, @Nullable Class<T> type);使用 这两个是Cache 接口要求的
@Override
protected Object lookup(Object key) {
byte[] value = cacheWriter.get(name, createAndConvertCacheKey(key));
if (value == null) {
return null;
}
return deserializeCacheValue(value);
}
在基础存储中执行实际查找。
说明:lookup 简单理解,向上看给上面用的,然后翻看RedisCache的 AbstractValueAdaptingCache 父类。
@Override
public ValueWrapper get(Object key) {
Object value = lookup(key);
return toValueWrapper(value);
}
@Overridepublic <T> T get(Object key, @Nullable Class<T> type) {
Object value = fromStoreValue(lookup(key));
if (value != null && type != null && !type.isInstance(value)) {
throw new IllegalStateException(
"Cached value is not of required type [" + type.getName() + "]: " + value);
}
return (T) value;
}
@Nullable
protected abstract Object lookup(Object key);
原来如此,标准模板方法 004-行为型-02-模板方法模式(Template Method)
其一、ValueWrapper get(Object key) 转换成ValueWrapper
toValueWrapper
protected Cache.ValueWrapper toValueWrapper(@Nullable Object storeValue) {
return (storeValue != null ? new SimpleValueWrapper(fromStoreValue(storeValue)) : null);
}
fromStoreValue 判空,返回原值
protected Object fromStoreValue(@Nullable Object storeValue) {
if (this.allowNullValues && storeValue == NullValue.INSTANCE) {
return null;
}
return storeValue;
}
SimpleValueWrapper,其实也是没做任何事,只是ValueWrapper一下
public class SimpleValueWrapper implements ValueWrapper {
@Nullable
private final Object value;
public SimpleValueWrapper(@Nullable Object value) {
this.value = value;
}
@Override
public Object get() {
return this.value;
}
}
其二、T get(Object key, @Nullable Class<T> type) 转换成 具体类对象
取值,判空,强制转换
2、String getName() 缓存空间名
3、RedisCacheWriter getNativeCache() 返回底层本机缓存提供程序。
4、synchronized <T> T get(Object key, Callable<T> valueLoader) 返回缓存值
@Override
@SuppressWarnings("unchecked")
public synchronized <T> T get(Object key, Callable<T> valueLoader) {
ValueWrapper result = get(key);
if (result != null) {
return (T) result.get();
}
T value = valueFromLoader(key, valueLoader);
put(key, value);
return value;
}
首先调用父类的get,获取wrapper,有值强转回具体对象,否则会 valueFromLoader
valueFromLoader,从传入的方法loader加载value,
private static <T> T valueFromLoader(Object key, Callable<T> valueLoader) {
return valueLoader.call();
}
接下来put存入,返回具体对象
5、put(Object key, @Nullable Object value) 存值


//按key 缓存 值
@Override
public void put(Object key, @Nullable Object value) {
Object cacheValue = preProcessCacheValue(value); //空值处理
if (!isAllowNullValues() && cacheValue == null) {
throw new IllegalArgumentException(String.format(
"Cache ''%s'' does not allow ''null'' values. Avoid storing null via ''@Cacheable(unless=\"#result == null\")'' or configure RedisCache to allow ''null'' via RedisCacheConfiguration.", name));
}
cacheWriter.put(name, createAndConvertCacheKey(key), serializeCacheValue(cacheValue), cacheConfig.getTtl());
}
6、ValueWrapper putIfAbsent(Object key, @Nullable Object value) 如果传入key对应的value已经存在,就返回存在的value,不进行替换。如果不存在,就添加key和value,返回null.


/*
* <pre><code>
* Object existingValue = cache.get(key);
* if (existingValue == null) {
* cache.put(key, value);
* return null;
* } else {
* return existingValue;
* }
* </code></pre>
*/
@Override
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
Object cacheValue = preProcessCacheValue(value); //空值处理
if (!isAllowNullValues() && cacheValue == null) {
return get(key);//通过key去value值
}
byte[] result = cacheWriter.putIfAbsent(name, createAndConvertCacheKey(key), serializeCacheValue(cacheValue), cacheConfig.getTtl());//利用 缓存提供者 提供的处理
if (result == null) {
return null;
}
return new SimpleValueWrapper(fromStoreValue(deserializeCacheValue(result)));
}
7、evict(Object key) 清除 指定key缓存
//清除 指定key缓存
@Override
public void evict(Object key) {
cacheWriter.remove(name, createAndConvertCacheKey(key));
}
createAndConvertCacheKey,以及一些列的key处理


//序列化key
protected byte[] serializeCacheKey(String cacheKey) {
return ByteUtils.getBytes(cacheConfig.getKeySerializationPair().write(cacheKey));
}
//序列化值
protected byte[] serializeCacheValue(Object value) {
if (isAllowNullValues() && value instanceof NullValue) {
return BINARY_NULL_VALUE;
}
return ByteUtils.getBytes(cacheConfig.getValueSerializationPair().write(value));
}
//反序列化 值
@Nullable
protected Object deserializeCacheValue(byte[] value) {
if (isAllowNullValues() && ObjectUtils.nullSafeEquals(value, BINARY_NULL_VALUE)) {
return NullValue.INSTANCE;
}
return cacheConfig.getValueSerializationPair().read(ByteBuffer.wrap(value));
}
//key处理
protected String createCacheKey(Object key) {
String convertedKey = convertKey(key);
if (!cacheConfig.usePrefix()) {
return convertedKey;
}
return prefixCacheKey(convertedKey);
}
//key处理
protected String convertKey(Object key) {
TypeDescriptor source = TypeDescriptor.forObject(key);
if (conversionService.canConvert(source, TypeDescriptor.valueOf(String.class))) {
return conversionService.convert(key, String.class);
}
Method toString = ReflectionUtils.findMethod(key.getClass(), "toString");
if (toString != null && !Object.class.equals(toString.getDeclaringClass())) {
return key.toString();
}
throw new IllegalStateException(
String.format("Cannot convert %s to String. Register a Converter or override toString().", source));
}
//key处理
private byte[] createAndConvertCacheKey(Object key) {
return serializeCacheKey(createCacheKey(key));
}
//key处理
private String prefixCacheKey(String key) {
// allow contextual cache names by computing the key prefix on every call.
return cacheConfig.getKeyPrefixFor(name) + key;
}
8、clear() 清除name下所有的key
//清除name下所有的key
@Override
public void clear() {
byte[] pattern = conversionService.convert(createCacheKey("*"), byte[].class);
cacheWriter.clean(name, pattern);
}
第一步获取key pattern;第二步清除 查看 RedisCacheWriter的子类DefaultRedisCacheWriter的
void clean(String name, byte[] pattern)
取出匹配的key,删除掉


@Override
public void clean(String name, byte[] pattern) {
Assert.notNull(name, "Name must not be null!");
Assert.notNull(pattern, "Pattern must not be null!");
execute(name, connection -> {
boolean wasLocked = false;
try {
if (isLockingCacheWriter()) {
doLock(name, connection);
wasLocked = true;
}
byte[][] keys = Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet())
.toArray(new byte[0][]);
if (keys.length > 0) {
connection.del(keys);
}
} finally {
if (wasLocked && isLockingCacheWriter()) {
doUnlock(name, connection);
}
}
return "OK";
});
}
: No JAAS configuration section named ''Client'' was found in specified JAAS configuration file:
zookeeper.ClientCnxn(line:957) : SASL configuration failed: javax.security.auth.login.LoginException: No JAAS configuration section named ''Client'' was found in specified JAAS configuration file: ''C:\Users\ADMINI~1\AppData\Local\Temp\jaas9138331021728969462.conf''. Will continue connection to Zookeeper server without SASL authentication, if Zookeeper server allows it.
java.net.SocketTimeoutException: callTimeout=60000, callDuration=60110: Call to master/192.168.7.202:16020 failed on local exception: org.apache.hadoop.hbase.ipc.CallTimeoutException: Call id=2, waitTime=60009, rpcTimeout=60000 row
@Configuration @AutoConfigureAfter @Autowired
如何解决@Configuration @AutoConfigureAfter @Autowired?
为什么不需要 brokerMessageConfiguration.class @AutoConfigureAfter(value = {RabbitProducerDataSourceConfiguration.class})
但是RabbitProducerMyBatisConfiguration.class 需要@AutoConfigureAfter(value = {RabbitProducerDataSourceConfiguration.class})
谢谢您的回答!
@Slf4j
@Configuration
@PropertySource({"classpath:rabbit-producer-message.properties"})
public class RabbitProducerDataSourceConfiguration {
@Value("${rabbit.producer.druid.type}")
private Class<? extends DataSource> dataSourceType;
@Bean(name ="rabbitProducerDataSource")
@ConfigurationProperties(prefix = "rabbit.producer.druid.jdbc")
public DataSource rabbitProducerDataSource() throws sqlException {
DataSource rabbitProducerDataSource = DataSourceBuilder.create().type(dataSourceType).build();
log.info("============= rabbitProducerDataSource : {} ================",rabbitProducerDataSource);
return rabbitProducerDataSource;
}
public DataSourceProperties primaryDataSourceProperties(){
return new DataSourceProperties();
}
public DataSource primaryDataSource(){
return primaryDataSourceProperties().initializeDataSourceBuilder().build();
}
}
二号
@Configuration
@AutoConfigureAfter(value = {RabbitProducerDataSourceConfiguration.class})
public class RabbitProducerMyBatisConfiguration {
@Resource(name= "rabbitProducerDataSource")
private DataSource rabbitProducerDataSource;
@Bean(name="rabbitProducersqlSessionFactory")
public sqlSessionFactory rabbitProducersqlSessionFactory(DataSource rabbitProducerDataSource) {
sqlSessionfactorybean bean = new sqlSessionfactorybean();
bean.setDataSource(rabbitProducerDataSource);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
sqlSessionFactory sqlSessionFactory = bean.getobject();
if (sqlSessionFactory != null) {
sqlSessionFactory.getConfiguration().setCacheEnabled(Boolean.TRUE);
}
return sqlSessionFactory;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Bean(name="rabbitProducersqlSessionTemplate")
public sqlSessionTemplate rabbitProducersqlSessionTemplate(sqlSessionFactory sqlSessionFactory) {
return new sqlSessionTemplate(sqlSessionFactory);
}
}
3号
@Configuration
public class brokerMessageConfiguration {
@Autowired
private DataSource rabbitProducerDataSource;
@Value("classpath:rabbit-producer-message-schema.sql")
private Resource schemaScript;
@Bean
public DataSourceInitializer initDataSourceInitializer() {
System.err.println("--------------rabbitProducerDataSource-----------:" + rabbitProducerDataSource);
final DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(rabbitProducerDataSource);
initializer.setDatabasePopulator(databasePopulator());
return initializer;
}
private DatabasePopulator databasePopulator() {
final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(schemaScript);
return populator;
}
}
为什么不需要 brokerMessageConfiguration.class @AutoConfigureAfter(value = {RabbitProducerDataSourceConfiguration.class})
但是RabbitProducerMyBatisConfiguration.class 需要@AutoConfigureAfter(value = {RabbitProducerDataSourceConfiguration.class})
谢谢您的回答!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
apache configuration directives
A. Directory Indexes (from mod_autoindex.c)
When you access a directory and there is no default file found in this directory AND Apache Options Indexes is not enabled for this directory. A.1. DirectoryIndex option example
DirectoryIndex index.html default.php welcome.php A.2. Options Indexes option
If set, apache will list the directory content if no default file found (from the above option) If none of the conditions above is satisfied
You will receive a 403 Forbidden Recommendations
You should not allow directory listing unless REALLY needed.
Restrict the default index DirectoryIndex to the minimum.
If you want to modify, restrict the modification to the needed directory ONLY, for instance, use .htaccess files, or put your modification inside the <Directory /my/directory> directive
B. deny,allow directives (Apache 2.2)
Mentioned by @Radu, @Simon A. Eugster in the comments You request is denied, blacklisted or whitelisted by those directives.
I will not post a full explanation, but I think some examples may help you understand, in short remember this rule:
IF MATCHED BY BOTH, THE LAST IS WILL WIN Order allow,deny
Deny will win if matched by both directives (even if an allow directive is written after the deny in the conf) Order deny,allow
allow will win if matched by both directives Example 1
Order allow,deny Allow from localhost mydomain.com
Only localhost and *.mydomain.com can access this, all other hosts are denied Example 2
Order allow,deny Deny from evil.com Allow from safe.evil.com # <-- has no effect since this will be evaluated first
All requests are denied, the last line may trick you, but remember that if matched by both the last win rule (here Deny is the last), same as written:
Order allow,deny Allow from safe.evil.com Deny from evil.com # <-- will override the previous one
Example 4
Order deny,allow Allow from site.com Deny from untrusted.site.com # <-- has no effect since this will be matched by the above Allow
directive
Requests are accepted from all hosts Example 4: typical for public sites (allow unless blacklisted)
Order allow,deny Allow from all Deny from hacker1.com Deny from hacker2.com
Example 5: typical for intranet and secure sites (deny unless whitelisted)
Order deny,allow Deny from all Allow from mypc.localdomain Allow from managment.localdomain
C. Require directive (Apache 2.4)
Apache 2.4 use a new module called mod_authz_host
Require all granted => Allow all requests
Require all denied => Deny all requests
Require host safe.com => Only from safe.com are allowed D. Files permissions
One thing that most people do it wrong is configuring files permissions,
The GOLDEN RULE is
STARTS WITH NO PERMISSION AND ADD AS PER YOUR NEED
In linux:
Directories should have the Execute permission
Files should have the Read permission
YES, you are right DO NOT ADD Execute permission for files
for instance, I use this script to setup the folders permissions
setting permissions for /var/www/mysite.com
read permission ONLY for the owner
chmod -R /var/www/mysite.com 400
add execute for folders only
find /var/www/mysite.com -type d -exec chmod -R u+x {} ;
allow file uploads
chmod -R /var/www/mysite.com/public/uploads u+w
allow log writing to this folder
chmod -R /var/www/mysite.com/logs/
关于configuration虚拟主机和本地主机redirect到xampp文件夹和xampp配置虚拟主机的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于006-spring cache-缓存原理-SimpleCacheConfiguration、RedisCacheConfiguration原理实现、: No JAAS configuration section named ''Client'' was found in specified JAAS configuration file:、@Configuration @AutoConfigureAfter @Autowired、apache configuration directives等相关知识的信息别忘了在本站进行查找喔。
本文标签: