Skip to content

Navigation

Martin Lippert edited this page May 21, 2019 · 17 revisions

Go to symbol in file/project/workspace

Easy navigation to Spring-specific elements of your source code.

Shortcuts

  • Eclipse: Cmd-6 (symbols in workspace), Cmd-6 again (symbols in project, new in 4.1.1), Cmd-6 again (symbols in file)
  • Code: Cmd-Shift-O (symbols in file), Cmd-T (symbols in workspace)
  • Atom: not available yet (symbols in file show up in outline view)

Use Ctrl on windows/linux in place of Cmd key.

Annotations

All Spring annotations from the source code in the workspace are in the list of symbols. They are prefixed with @ as the other Spring symbols. It is best to type a specific annotation such as @Autowired in the search box to narrow down the list of symbols to specific type of annotation being searched for. The annotation synbol entry in the list consits of:

  • Annotation label (i.e. @Autowired, @Qualifier etc.)
  • Path to the resource containing the annotation symbol

Clicking on the annotation entry in the list navigates to the position in the source code resource where the annotation is located

Beans

All Beans symbols are prefixed with @+. Typing @+ is the search box lists only Bean symbols defined in the source code.

A common bean entry defined with an annotation consists of:

  • Bean ID
  • Annotation label including annotation "Meta Inheritance Relationship", i.e. any Controller is a Component
  • Path to the resource containing the bean definition

There are bean definitions without annotations such as Spring Data Repository beans. These consist of:

  • Bean ID
  • Type of model objects stored by the repository and Java type of the repository
  • Path to the resource containing the bean definition

Clicking on the bean entry in the list navigates to the position in the source code resource where the bean is defined.

Bean definitions from Spring XML config files (new in 4.1.1)

Spring Tools 4 are able to parse Spring XML config files for bean definitions. Therefore all XML files in the workspace are scanned and analyzed for Spring bean definitions. At the moment only direct bean definitions in the style of:

    <bean id="name" class="org.test.TheClassOfTheBean"/>

As a result, a bean symbol in generated and showing up in the list of symbols as: @+ 'name' TheClassOfTheBean.

Since this is an experimental feature, you need to enable it via the preferences first, and restart the tooling afterwards in order to trigger the initial scanning of Spring XML config files.

Request Mappings

All Request Mapping symbols are prefixed with @/. Typing @/ in the search box lists only Request Mapping symbols.

A common Request Mapping symbol entry consists of:

  • Path of the Request Mapping
  • Type of the RequestMapping or content type or other auxiliary data if applicable
  • Path to the resource containing the bean definition

Clicking on the Request Mapping entry in the list navigates to the position in the source code resource where the Request Mapping is defined.

Examples

  • @/ shows all defined request mappings (mapped path, request method, source location)
  • @+ shows all defined beans (bean name, bean type, source location)
  • @> shows all functions (prototype implementation) (see the Spring Cloud Function project)
  • @ shows all Spring annotations in the code
  • // shows all request mappings of all running Spring Boot apps and opens a browser for the selected endpoint (this only works in the global 'go to symbol' view - after pressing Cmd-6 twice)

Additional options (new in 4.2.0)

If you are working with large workspaces and are observing large amounts of memory being used by the language server process behind the scenes, you have two new options to deal with this situation:

  • if you are running on Eclipse, you can pass custom VM arguments to that process, for example to increase the max heap size of that JVM.

  • (new in 4.2.1) the option to ignore method bodies while scanning for symbols in Java source files is no longer necessary to reduce the amount of memory used and improve the performance at the cost of loosing symbols for Webflux routes. Instead, the symbol scanning ignores method bodies by default now and does a second pass including the method bodies for those files that include web flux route definitions only.

In addition to that the new cache mechanism will also help in this situation, see the next section.

Caching (new in 4.2.0)

The symbol indexing infrastructure uses a cache now to store and retrieve generated symbols across language server startups. That means, as long as you don't change the projects or the files, the next time the language server starts up, all the symbols will be retrieved from a cache and no source code parsing will happen.

The cache will be invalidated (on a per-project base) automatically whenever libraries on the classpath of that project change or source files inside of the project change. This causes the symbol indexer to re-index the project (and update the cache).

The cached data is stored in the ~/.sts4/.symbolCache/ directory. You will see a bunch of JSON files appearing in that directory once the indexer stores the cache. The mechanism tries to delete outdated data from that directory automatically, but in case something goes wrong, feel free to wipe out the cache directory manually.

The cache is enabled by default. You can switch it off by passing -Dboot.ls.symbols.caching.enabled=false to the language server.

Go to definition (new in 4.2.2)

Go to definition support for Spring XML config files (new in 4.2.2)

The support for Spring XML config files now includes direct support for "go to definition" for:

  • jump to bean class
  • jump to bean definition (across Java source and XML files)
  • jump to property definition
Clone this wiki locally