Giter Site home page Giter Site logo

spring-depend's Introduction

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

spring-depend's People

Contributors

dependabot[bot] avatar formatq avatar jillesvangurp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

spring-depend's Issues

dependency result reversed

@bean("shiroFilter")
@dependsOn("securityManager")
public ShiroFilterFactoryBean shiroFilter(DefaultSecurityManager securityManager){
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
}
when I used the above code,the result is "CREATE (securityManager)-[:DEPENDSON]->(shiroFilter)"

the correct dependency relation should be shiroFilter depends on securityManager
I think because the shiroFilter used securityManager,so the securityManager should be loaded by spring earlier than shiroFIlter.It 's should be like securityManager DEPENDSON shiroFilter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.