开发Spring应用程序时最常见的错误是什么?

时间:2021-08-27 15:49:40

I'm currently preparing my Bachelor thesis at the University of Münster. I plan to automatically identify typical problems in Spring configurations. There are a lot of tools at the market which perform static code analysis to find bugs or problems. These obviously can't detect problems which only appear at runtime. I'm going to analyse the ApplicationContext of a Spring application and find misconfiguration by using reflection and the analysis of the bean graph.

我目前正在明斯特大学准备我的学士论文。我计划自动识别Spring配置中的典型问题。市场上有很多工具可以执行静态代码分析来查找错误或问题。这些显然无法检测仅在运行时出现的问题。我将分析Spring应用程序的ApplicationContext,并通过使用反射和bean图分析来查找错误配置。

Example: A simple example is, if somebody wants to make a class or method transaction secure by using annotations. He will normally add a @Transactional-tag above the class or method, but if the application isn't configured right and there is no transaction manager registered to the ApplicationContext, which observes annotations, then the tag will be ignored. No error message will arise, which is the reason that these types of problems are hard to find so far.

示例:一个简单的示例是,如果有人想通过使用注释使类或方法事务安全。他通常会在类或方法上面添加一个@Transactional-tag,但是如果没有正确配置应用程序并且没有向ApplicationContext注册的事务管理器,它会观察注释,那么标记将被忽略。不会出现任何错误消息,这就是迄今为止很难找到这些类型的问题的原因。

Question: Which are the most common mistakes or architectural faults caused by misconfiguration using the spring mechanisms, which can be detected by a dynamic analysis? Are there any projects which attend to do something similar?

问题:使用弹簧机制的错误配置导致的最常见错误或架构故障是哪些,可以通过动态分析检测到?是否有任何项目可以做类似的事情?

P.S. In the course of my thesis I will develop a prototype which can detect these kinds of problems and open source it henceforth. :)

附:在我的论文中,我将开发一个原型,可以检测这些问题并从此开源。 :)

1 个解决方案

#1


0  

From the Spring related questions I have answerd, your Example (not correct initialized @Transaction) is one of the most asked Problems. But with a small tweek: Often the Problem is that somebody tryes this:

从我回答的Spring相关问题来看,你的例子(不正确的初始化@Transaction)是最常问的问题之一。但是通过一个小小的调整:通常问题是有人尝试这个:

@Service
public class SomeService() {

  @Transaction
  public void save(Some thing) {
      ...
  }

  public void doSomeThing(Some thing) {
     ...
     this.save(thing);
  }
}

And then they are wondering why the @Transactional annotation is not taken in account when using doSomeThing.

然后他们想知道为什么在使用doSomeThing时不考虑@Transactional注释。

The problem is that this works only this real AspectJ and not with this Proxy AOP.

问题是这只适用于这个真正的AspectJ而不是这个代理AOP。

#1


0  

From the Spring related questions I have answerd, your Example (not correct initialized @Transaction) is one of the most asked Problems. But with a small tweek: Often the Problem is that somebody tryes this:

从我回答的Spring相关问题来看,你的例子(不正确的初始化@Transaction)是最常问的问题之一。但是通过一个小小的调整:通常问题是有人尝试这个:

@Service
public class SomeService() {

  @Transaction
  public void save(Some thing) {
      ...
  }

  public void doSomeThing(Some thing) {
     ...
     this.save(thing);
  }
}

And then they are wondering why the @Transactional annotation is not taken in account when using doSomeThing.

然后他们想知道为什么在使用doSomeThing时不考虑@Transactional注释。

The problem is that this works only this real AspectJ and not with this Proxy AOP.

问题是这只适用于这个真正的AspectJ而不是这个代理AOP。