2016-12-04 48 views
0

SessionAttributeで異常な動作が発生しました。 NafControllerとStatsControllerという2つのコントローラで使用するために、nafSelectionという名前のSessionAttributeを定義しました。すべてのコントローラでSpring MVC SessionAttributeが初期化されていません(Spring Boot 1.4.2)

NafControllerを通過すると、SessionAttributeが作成され、StatsControllerがそれを使用できます。最初に、私はStatsControllerを使用していますが、「タイプNafSelectionのセッション属性 'nafSelection'が見つかりません」というエラーがあります。

@ControllerAdvice('com.dyndata.sirene.controllers') 
class ModelAdvice { 
    @ModelAttribute("nafSelection") 
    NafSelection newSelection() { 
     new NafSelection() 
    } 
} 

そして、私は私の2つのコントローラにセッション属性を宣言します:モデルを共有するための

は私がControllerAdviceをコード化されてきた属性

@Controller 
@SessionAttributes("nafSelection") 
class NafController { 
    private static Logger logger = Logger.getLogger(NafController.class.name); 

    @RequestMapping('/naf') 
    def naf() { 
     'naf' 
    } 

    @RequestMapping(path = '/naf/{nafCode}', method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 
    @ResponseBody 
    def affNafCode(@PathVariable String nafCode, @SessionAttribute NafSelection nafSelection) { 
     logger.info("Adds the NAF " + nafCode) 
     nafSelection.nafs << nafCode 

     return new Counter(count: 5600) 
    } 

    @RequestMapping(path = '/naf/{nafCode}', method = RequestMethod.DELETE) 
    @ResponseBody 
    def delNafCode(@PathVariable String nafCode, @SessionAttribute NafSelection nafSelection) { 
     logger.info("Deletes the NAF " + nafCode) 
     nafSelection.nafs.remove(nafCode) 

     return new Counter(count: 80000) 
    } 
} 

二コントローラ:

@Controller 
@SessionAttributes("nafSelection") 
class StatsController { 
    private static Logger logger = Logger.getLogger(StatsController.class.name); 

    @RequestMapping(path = '/stats') 
    def stats(@SessionAttribute NafSelection nafSelection) { 
     'stats' 
    } 
} 

セッション属性がNatsControllerによってうまく管理され、StatsControllerによってうまく管理されないのはなぜですか?

注:私のコードはGroovy言語です。

答えて

0

私が見つけた:)

私はModelAttributeの代わりSessionAttributeとしてメソッドパラメータをマークしなければなりません。

関連する問題