Should all be spring be managed in the spring application?

We are working on a new application and want to use Spring (college project!)

When you write a new Spring application, should each object be Spring introduced?

class A {
    ...
    AHelper helper = new AHelper();
    helper.doSomething();
    ...
}

class AHelper {
    public void doSomething(){}
}
  • In this case, if AHelper is introduced to Spring using a setter? If class A depends on 5 helpers, should they all be introduced? This is best practice, and if so, what do we get from it?

  • In addition, if the AHelper class depends on AHelperHelper and which, in turn, depends on AHelperHelperHelper, whether to configure the entire dependency chain in XML. This seems bad to me!

+5
source share
3 answers

I saw projects into which every object was introduced, and this is a nightmare.

, , , , Spring beans, :

  • , ,
  • Spring AoP (, ..).
  • , , .

, Spring - , / , , JMX ( Spring AoP) .

+5

, , beans, . , , , . .

, :

  • , - Spring beans. , , , , beans .

  • Model Spring beans. , . , , beans, .

  • DTO, VO... , , , .

  • . :

    • : , beans. .

    • , , : .

    • , CsvFileConstructor: -, , . , ( : , , ...), , beans.

  • , ,...: , beans.

+3

Not all. But in this case, it would probably be a good idea, yes. What you get is the unit-test feature Aby introducing a layout into it AHelper. You could get many other things (security, transactional aspects, etc.), but it depends on the context and on which objects Aand AHelper.

The same applies to your entire chain. Please note that XML is not the preferred way to customize your Spring application. Annotations are easier to use and allow you to have a minimal XML configuration file.

+2
source

All Articles