Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

When using the following code snippet:

public class MyUrls {

    // properties get initialized using static{...}
    public final static String URL_HOMEPAGE = properties.getProperty("app.homepage");    

}

@Controller
public class HomepageController {

    @RequestMapping(MyUrls.URL_HOMEPAGE)
    public String homepage() {
        return "/homepage/index";
    }

}

I get the following error:

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

But in fact, URL_HOMEPAGE does be a constant, since it is declared as public final static. Am I wrong? How to solve this issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...