The value for annotation attribute RequestMapping.value must be a constant expression

前端 未结 2 690
灰色年华
灰色年华 2020-12-19 11:44

When using the following code snippet:

public class MyUrls {

    // properties get initialized using static{...}
           


        
相关标签:
2条回答
  • 2020-12-19 12:15

    Whilst URL_HOMEPAGE is a constant it's value may not be, it can only be determined at runtime. I believe that values used in annotations must be resolvable at compile-time.

    0 讨论(0)
  • 2020-12-19 12:27

    It is a constant, but it is initialized after the request mapping is initialized. You are calling properties.getProperty("app.homepage"); When the classloader loads you class, the URL_HOMEPAGE is not initialized yet, hence the error.
    You need to give as a parameter an initialized string, such as "/path/subpath"

    0 讨论(0)
提交回复
热议问题