2016-07-12 10 views
0

Springを使用してWebSocketサーバーアプリケーションを開発しています。私は、ユーザーがされた方法を示し@AuthorizationRequired注釈を加え、私は、ユーザーがトークンによって、すべての着信要求を許可することにしたいので、私はアスペクトUserAuthorization注釈で実行されないSpring aopの側面

package com.berrigan.axevor.authorization; 

import org.aspectj.lang.ProceedingJoinPoint; 
import org.aspectj.lang.annotation.Around; 
import org.aspectj.lang.annotation.Aspect; 
import org.springframework.stereotype.Component; 


@Aspect 
@Component 
public class UserAuthorization { 
    @Around("@annotation(com.berrigan.axevor.authorization.AuthorizationRequired)") 
    public void authorize(ProceedingJoinPoint jp) throws Throwable{ 
     System.out.println("\n\n\n\n\Works\n\n\n\n\n\n"); 
     jp.proceed(); 
    } 
} 

を作成 クラスPlayerHandler

import org.springframework.web.socket.WebSocketSession; 
import org.springframework.web.socket.handler.TextWebSocketHandler; 

import java.io.IOException; 

/** 
* Created by kris on 11.07.16. 
*/ 
public class PlayerHandler extends TextWebSocketHandler{ 
    public PlayerHandler(){} 

    @Override 
    @AuthorizationRequired 
    public void handleTextMessage(WebSocketSession session, TextMessage tm) throws IOException { 
     session.sendMessage(tm); 
    } 
} 

承認される予定です。残念なことに、メソッドの権限が呼ばれることはありません。メインクラスに次のコードを追加して、Beanが作成されるかどうかを確認しました。

UserAuthorization ua = ctx.getBean(UserAuthorization.class); // ApplicationContext 
if(au == null) System.out.println("is null") 

しかし、私はそのようなログを取得しません。 私の春の設定

@EnableAutoConfiguration 
@Configuration 
@EnableAspectJAutoProxy 
@Import({com.berrigan.axevor.websocket.WebSocketConfig.class}) 
@ComponentScan(basePackages = {"com.berrigan.axevor"}) 
public class Config {} 

注釈コード:

@Retention(RetentionPolicy.RUNTIME) 
@Target(ElementType.METHOD) 
public @interface AuthorizationRequired{} 

@Configuration @EnableWebSocket

public class WebSocketConfig implements WebSocketConfigurer{ 
    @Override 
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry){ 
     registry.addHandler(playerHandler(), "/game").setAllowedOrigins("*"); 
    } 

    @Bean 
    public WebSocketHandler playerHandler(){ 
     return new PlayerHandler(); 
    } 
} 
+1

あなたの注釈を見てみましょう。あなたがそれをしている間に[mcve]を投稿してください。 –

+0

ええ、これはすべて基本的な前提で、うまく動作します。 [mcve]を投稿してください。 –

+0

このコードは実行可能にする必要があります。実行するためにspring-bootを使用しています – Berrigan

答えて

0

ソリューション見つかった、破損したpom.xmlファイル。それを再生した後、すべてが魅力のように動作します

関連する問題