# 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<String, Set<String>> 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<String, Set<String>> 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<String> 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<Class<?>> getConfigurationGraph(Class<?> configurationClass)` return a graph of your `@Configuration` classes by following the imports from the specified root class.
- `Map<Integer, Set<Class<?>>> 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
```
<dependency>
<groupId>com.jillesvangurp</groupId>
<artifactId>spring-depend</artifactId>
<!-- check maven central for latest, Readme's get out of date so easily ... -->
<version>0.2</version>
</dependency>
```
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)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Java SSM项目是一种使用Java语言和SSM框架(Spring + Spring MVC + MyBatis)开发的Web应用程序。SSM是一种常用的Java开发框架组合,它结合了Spring框架、Spring MVC框架和MyBatis框架的优点,能够快速构建可靠、高效的企业级应用。 1. Spring框架:Spring是一个轻量级的Java开发框架,提供了丰富的功能和模块,用于开发企业级应用。它包括IoC(Inverse of Control,控制反转)容器、AOP(Aspect-Oriented Programming,面向切面编程)等特性,可以简化开发过程、提高代码的可维护性和可测试性。 2. Spring MVC框架:Spring MVC是基于Spring框架的Web框架,用于开发Web应用程序。它采用MVC(Model-View-Controller,模型-视图-控制器)的架构模式,将应用程序分为模型层、视图层和控制器层,提供了处理请求、渲染视图和管理流程的功能。 3. MyBatis框架:MyBatis是一个持久层框架,用于与数据库进行交互。它提供了一种将数据库操作与Java对象映射起来的方式,避免了手动编写繁琐的SQL语句,并提供了事务管理和缓存等功能,简化了数据库访问的过程
资源推荐
资源详情
资源评论
收起资源包目录
Spring Boot示例项目,包含指标、日志和分布式跟踪的工具(高分项目).zip (27个子文件)
spring-depend-master
pom.xml 12KB
formatter.xml 31KB
src
test
java
com
jillesvangurp
springdepend
spring
Thingy.java 238B
BeanConfig2.java 700B
Thingy3.java 302B
Thingy2.java 362B
scan
BeanName11.java 247B
BeanNameCommon.java 146B
BeanName21.java 247B
BeanName13.java 255B
BeanName32.java 244B
BeanName23.java 255B
BeanName31.java 248B
BeanName22.java 247B
BeanName.java 332B
BeanName12.java 248B
RootConfig.java 360B
BeanConfig1.java 366B
SpringDependencyAnalyzerTest.java 2KB
main
java
com
jillesvangurp
springdepend
SimpleGraph.java 5KB
SpringDependencyAnalyzer.java 11KB
json
BeanDependency.java 2KB
BeanDependencyStatistic.java 946B
LICENSE 1KB
neo4j.sh 207B
.gitignore 82B
README.md 5KB
共 27 条
- 1
资源评论
若明天不见
- 粉丝: 1w+
- 资源: 272
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功