我需要在我的spring boot应用程序中禁用redis。
我从网上学了很多技巧,但都没有成功。
我的应用程序。属性,它有以下行:

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。
行动:
考虑在配置中定义一个类型为“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);   }
}

这里是我的聊天配置:
@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。

最佳答案

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

@SpringBootApplication(exclude = RedisAutoConfiguration.class)

10-05 22:54