gpt4 book ai didi

java - Spring Boot 禁用 Redis 服务器

转载 作者:可可西里 更新时间:2023-11-01 11:48:45 24 4
gpt4 key购买 nike

我需要在我的 Spring Boot 应用程序中禁用 redis。我遵循了网上的很多提示,但没有成功。

我的 application.properties,它有这一行:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration

spring.data.redis.repositories.enabled=false

当我尝试启动我的应用程序时,我得到:

描述:

org.springframework.session.web.socket.config.annotation.AbstractSessionWebSocketMessageBrokerConfigurer 中的字段 sessionRepository 需要找不到类型为“org.springframework.session.SessionRepository”的 bean。

Action :

考虑在您的配置中定义类型为“org.springframework.session.SessionRepository”的 bean。

我正在运行的应用程序是关于 WebSocket 的测试。它工作得很好,但对于业务,我需要禁用 Redis。请提供任何帮助。

提前致谢!!

这是我的代码: 我的主课:

public class WebSocketChatApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
SpringApplication.run(WebSocketChatApplication.class, args);
}

@Override protected SpringApplicationBuilder
configure(SpringApplicationBuilder application) { return
return application.sources(WebSocketChatApplication.class); }
}

这是我的 ChatConfig:

@Configuration
@EnableConfigurationProperties(ChatProperties.class)
public class ChatConfig {

@Autowired
private ChatProperties chatProperties;

@Bean
@Description("Tracks user presence (join / leave) and broacasts it to all connected users")
public PresenceEventListener presenceEventListener(SimpMessagingTemplate messagingTemplate) {
PresenceEventListener presence = new PresenceEventListener(messagingTemplate, participantRepository());
presence.setLoginDestination(chatProperties.getDestinations().getLogin());
presence.setLogoutDestination(chatProperties.getDestinations().getLogout());
return presence;
}

@Bean
@Description("Keeps connected users")
public ParticipantRepository participantRepository() {
return new ParticipantRepository();
}

@Bean
@Scope(value = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Description("Keeps track of the level of profanity of a websocket session")
public SessionProfanity sessionProfanity() {
return new SessionProfanity(chatProperties.getMaxProfanityLevel());
}

@Bean
@Description("Utility class to check the number of profanities and filter them")
public ProfanityChecker profanityFilter() {
ProfanityChecker checker = new ProfanityChecker();
checker.setProfanities(chatProperties.getDisallowedWords());
return checker;
}

/*@Bean(initMethod = "start", destroyMethod = "stop")
@Description("Embedded Redis used by Spring Session")
public RedisServer redisServer(@Value("${redis.embedded.port}") int port) throws IOException {
return new RedisServer(port);
}*/

这是我的 WebSocketConfig:

@Configuration
@EnableWebSocketMessageBroker


public class WebSocketConfig extends
AbstractSessionWebSocketMessageBrokerConfigurer<Session> {



@Override
protected void configureStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue/", "/topic/", "/exchange/");
//registry.enableStompBrokerRelay("/queue/", "/topic/", "/exchange/");
registry.setApplicationDestinationPrefixes("/app");
}

安全配置类:

@EnableWebSecurity

@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

private static final String SECURE_ADMIN_PASSWORD = "rockandroll";

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.formLogin()
.loginPage("/index.html")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/chat.html")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/index.html")
.permitAll()
.and()
.authorizeRequests()
.antMatchers("/js/**", "/lib/**", "/images/**", "/css/**", "/index.html", "/").permitAll()
.antMatchers("/websocket").hasRole("ADMIN")
.requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ADMIN")
.anyRequest().authenticated();
http.cors().configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues());


}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

auth.authenticationProvider(new AuthenticationProvider() {

@Override
public boolean supports(Class<?> authentication) {
return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication);
}

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;

List<GrantedAuthority> authorities = SECURE_ADMIN_PASSWORD.equals(token.getCredentials()) ?
AuthorityUtils.createAuthorityList("ROLE_ADMIN") : null;

return new UsernamePasswordAuthenticationToken(token.getName(), token.getCredentials(), authorities);
}
});
}

我认为这是最重要的。剩下的是一个 RestController 和几个 DTO 对象。就像我已经说过的那样,它工作得很好,但我需要禁用 Redis。

最佳答案

您可以尝试禁用 Redis auto-configuration从 Spring boot 应用程序类中查看您是否有任何不同的行为。

@SpringBootApplication(exclude = RedisAutoConfiguration.class)

关于java - Spring Boot 禁用 Redis 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54523402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com