小编Vir*_*rat的帖子

Swagger 中的 @ApiOperation 与 @ApiResponse

@ApiOperation有一个属性response,我们可以将响应类型传递给它。在@ApiResponse我们也有一个属性response,这是我们可以通过响应类型。那么它们之间的确切区别是什么?

swagger spring-boot swagger-2.0

8
推荐指数
2
解决办法
2万
查看次数

spring boot 连接多个数据库

我需要连接到我的项目中的两个数据库。所以我创建了两个配置文件。

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories( basePackages = {"com.virat.webservices.datastore.v1.Repo" } )
@EntityScan("com.virat.webservices.datastore.v1.Model")
public class V1DBConfig {

@Primary
@Bean( name = "dataSource" )
@ConfigurationProperties( prefix = "v1.datasource" )
public DataSource dataSource()
{
    return DataSourceBuilder.create().build();
}

@Primary
@Bean( name = "entityManagerFactory" )
public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder builder,
        @Qualifier( "dataSource" ) DataSource dataSource )
{
    return builder.dataSource(dataSource).packages("com.virat.webservices.datastore.v1.Model")
            .persistenceUnit("db1").build();
}

@Primary
@Bean( name = "transactionManager" )
public PlatformTransactionManager transactionManager(
        @Qualifier( "entityManagerFactory" ) EntityManagerFactory entityManagerFactory )
{
    return new JpaTransactionManager(entityManagerFactory);
}
}
Run Code Online (Sandbox Code Playgroud)

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories( entityManagerFactoryRef …
Run Code Online (Sandbox Code Playgroud)

java spring-data spring-boot

6
推荐指数
2
解决办法
6692
查看次数

更改spring security中的登录服务URL

嗨,我已经使用 JWT 过滤器在我的 Spring Boot Web 应用程序中实现了 Spring 安全性。但默认身份验证发生在 url http://localhost:8080/login。如何更改/login为我需要的一些网址/rest/auth/login

我的WebSecurity班级是

@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter {

@Autowired
private UserDetailsService userDetailsService;

@Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;

public WebSecurity( UserDetailsService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder )
{
    this.userDetailsService = userDetailsService;
    this.bCryptPasswordEncoder = bCryptPasswordEncoder;
}

@Override
protected void configure( HttpSecurity http ) throws Exception
{
    http.cors().and().csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, "/rest/auth/**").permitAll()
            .antMatchers("/static/*").permitAll().antMatchers("/").permitAll()
            /* .anyRequest().authenticated() */.and()
            .addFilter(new JWTAuthenticationFilter(authenticationManager()))
            .addFilter(new JWTAuthorizationFilter(authenticationManager()));
}

@Override
public void configure( AuthenticationManagerBuilder auth ) throws Exception
{ …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-boot

5
推荐指数
2
解决办法
1万
查看次数

spring boot web socket中的实时通知

在我的应用程序中,我需要向特定用户发送实时通知。我的WebSocketConfig课如下,

    @Configuration
    @EnableWebSocketMessageBroker
    public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
        @Override
        public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
            stompEndpointRegistry.addEndpoint("/websocket-example")
                    .withSockJS();
        }

        @Override
        public void configureMessageBroker(MessageBrokerRegistry registry) {
            registry.enableSimpleBroker("/topic");
    }
}
Run Code Online (Sandbox Code Playgroud)

大多数时候信息会由服务器端发送。所以我还没有设置应用程序目的地。

在客户端,我订阅了目标“/topic/user”,

function connect() {
    var socket = new SockJS('/websocket-example');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function (frame) {
        setConnected(true);
        console.log('Connected: ' + frame);
        stompClient.subscribe('/topic/user', function (greeting) {
//            showGreeting(JSON.parse(greeting.body).content);
console.log("Received message through WS");
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

RestController我的一个方法中,我有一种方法可以将消息广播给所有连接的客户端。

    @GetMapping("/test")
    public void test()
    {
        template.convertAndSend("/topic/user", "Hurray");
    }
Run Code Online (Sandbox Code Playgroud)

直到这部分一切正常。我收到消息并正在登录到控制台。

现在,如果我只想将通知发送给特定用户,则必须使用template.convertAndSendToUser(String user, String …

java spring websocket spring-boot spring-websocket

5
推荐指数
1
解决办法
6767
查看次数