Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jillesvangurp/spring-depend
Tool for getting a spring bean dependency graph
https://github.com/jillesvangurp/spring-depend
dependency-graph dependency-injection java-8 neo4j spring
Last synced: 2 months ago
JSON representation
Tool for getting a spring bean dependency graph
- Host: GitHub
- URL: https://github.com/jillesvangurp/spring-depend
- Owner: jillesvangurp
- License: mit
- Created: 2017-02-08T10:01:57.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T10:02:44.000Z (8 months ago)
- Last Synced: 2024-09-27T21:41:53.865Z (4 months ago)
- Topics: dependency-graph, dependency-injection, java-8, neo4j, spring
- Language: Java
- Size: 43 KB
- Stars: 40
- Watchers: 5
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spring-depend
Tool for analyzing spring dependencies & exporting your dependencies to neo4j. Similar tools exist but they seem to be bundled with complicated IDE plugins or other stuff I don't really need/use. This makes standalone usage a bit hard. This is a standalone thing. All you need to use this is a spring application context.
To use:
- Add the dependency to spring-depend to your existing spring project
- Get a reference to your application context in one of the several ways that spring allows you to do this. Any instance of spring's `GenericApplicationContext` or one of the sub classes should work
- Do something like this:
```
SpringDependencyAnalyzer analyzer = new SpringDependencyAnalyzer(context);
analyzer.printReport();
System.out.println(analyzer.beanGraphCypher()) // copy paste in neo4j console & enjoy!
```Features:
- `Map> getBeanDependencies()` returns a map of all the beans in your context and their dependencies. Needing lots of things is a sign of low coherence and high coupling.
- `Map> getReverseBeanDependencies()` returns reverse dependencies. Being used a lot is a good thing; it indicates usefulness. Things that are rarely used might not need to be beans on the other hand.
- `SimpleGraph getBeanGraph()` a graph of the dependencies. (TODO: technically this is a reverse dependency graph that is generated from both the dependency and reverse dependency map. I need to add the ability to invert it.)
- `SimpleGraph> getConfigurationGraph(Class> configurationClass)` return a graph of your `@Configuration` classes by following the imports from the specified root class.
- `Map>> getConfigurationLayers(Class> configurationClass)` returns a tree map with the configuration classes ordered in layers by their dependencies on each other. The more layers you need, the more complex your spring dependencies are. Consider refactoring them to have less interdependencies. Untangling the the most coupled beans will likely clear this up.
- `String configurationGraphCypher(Class>)` returns neo4j cypher for your Spring configuration import dependencies in neo4j
- `String beanGraphCypher()` returns neo4j cypher for creating your spring bean dependency graph in neo4j
- `String getCircularDependencyStatisticJson()` return json report with all circular bean dependency. For example:
```
{
"createDate": "Feb 28, 2020 11:04:40 AM",
"allBeanCircularDependencyCount": 19,
"dependencyMap": {
"bean7": {
"injectedBeanCount": 1,
"injectedBeanNames": [
"bean6"
],
"circularDependencyCount": 5,
"circularDependencyDescriptions": [
"bean7-bean6-bean7",
"bean7-bean6-bean5-bean4-bean1-bean7",
"bean7-bean6-bean5-bean4-bean3-bean7",
"bean7-bean6-bean5-bean7",
"bean7-bean6-bean5-bean4-bean7"
]
},
"bean6": {
"injectedBeanCount": 2,
"injectedBeanNames": [
"bean5",
"bean7"
],
"circularDependencyCount": 4,
"circularDependencyDescriptions": [
"bean6-bean5-bean4-bean7-bean6",
"bean6-bean5-bean4-bean1-bean3-bean7-bean6",
"bean6-bean5-bean4-bean1-bean7-bean6",
"bean6-bean5-bean7-bean6"
]
}
}
```# Future work
When time allows, I might work on these topics a bit. Pull requests are welcome of course.- Better graph implementation than the rather limited `SimpleGraph` currently included. This was a quick and dirty job but it seems good enough.
- Fix the bean graph to not be a reverse dependency graph.
- Simple metrics for coherence and coupling.
- Test framework support so you can assert constraints on your dependencies and related metrics from a simple unit test.# Get it from Maven Central
```
com.jillesvangurp
spring-depend
0.2```
Note. the spring dependency in the pom is optional. This is so you can specify which spring version you use and avoid nasty conflicts. Anything recent (4.x and up) should pretty much work with this and perhaps older versions too.
# License
[MIT](LICENSE)