4

This question most likely has been asked before. But I couldn't find it because searching a real hashtag in Google seems to be difficult. I suppose it's not called a hashtag and it's one of the relatively rare moments where my English fails me (2nd language).

So despite this being a duplicate, I'd argue to keep it on the site so that it is easier searchable via Google (and the SO site itself!).

I have the following code.

@GetMapping("/users")
@Timed
@PreAuthorize("hasAuthority('ADMINISTRATOR') or #oauth2.hasScope('some-user-list')")
public ResponseEntity<List<UserDTO>> getAllUsers(@ApiParam Pageable pageable) {
    final Page<UserDTO> page = userService.getAllUsers(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/users");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}

What does the # mean (in particular for #oauth2, I know what authentication is and what oauth does, I just don't understand the # as a concept in Spring)? How is it called? This doesn't seem to pertain to the Java language itself, so how does Spring Boot call this concept?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Melvin Roest
  • 1,392
  • 1
  • 15
  • 31
  • 1
    I am prepared to take the hit. I know what I am doing is 'wrong' but I really could use the help! – Melvin Roest Aug 24 '18 at 10:42
  • 1
    @GhostCat times have changed, now it seems these questions are the cream of the crop ;) – Kayaman Aug 24 '18 at 10:42
  • 1
    The question has been answered, I found the right pages that I needed to find. Thank you everyone <3 – Melvin Roest Aug 24 '18 at 10:43
  • 1
    @Kayaman Wow, that worked out nicely. After putting my link here, some friendly person came in and downvoted that question. To quote a famous song: "No, i didn't expect that". – GhostCat Aug 24 '18 at 11:24
  • @GhostCat SO can be such a pain sometimes. I have very few questions, but still I've managed to get a +6/-6 [here](https://stackoverflow.com/questions/34197964/why-doesnt-springs-transactional-work-on-protected-methods) (now someone is probably going to downvote *that* ;). Not that I care about points that much, but I don't think it reflects the real value of the question. I guess "ignore and move on" is the only way to go. – Kayaman Aug 24 '18 at 11:55
  • 2
    @Kayaman Sure, but they are my babies you know. And it is less about the -1, it is more the really unexpected downvote ... and of course, *Socratic* is the last gold badge I am hunting (well, besides one more Steward). And every not well received question unhelps with that. – GhostCat Aug 24 '18 at 11:58

1 Answers1

8

It's part of the Spring Expression Language (Spring EL).

It allows you to write dynamic expressions, conditions and other things that would be impossible (or at least very clumsy) otherwise.

Similar expression languages exist in other frameworks (e.g. JSF EL), and they usually look very similar in syntax.

Kayaman
  • 72,141
  • 5
  • 83
  • 121