Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a hashtag ( # ) in Java/SpringBoot?

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?

like image 672
Melvin Roest Avatar asked Jan 27 '23 13:01

Melvin Roest


1 Answers

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.

like image 199
Kayaman Avatar answered Jan 31 '23 07:01

Kayaman