using @Autowired many times

Por Que

I'm very new to spring, so I might ask silly question but anyway...

I have built Spring MVC 4.0 application.

my settings are like this:

Controller >> Service >> DAO

in controller level I use about 4 to 5 different @Autowired variables like this

@Autowired
private ClientService clientService;
@Autowired
private CommentService commentService;
@Autowired
private SearchService searchService;

In Service level I Autowire also several DAOs

@Autowired
SearchDAO searchDAO;

@Autowired
private ActivityDAO activityDAO;

@Autowired
private UserService userService;

I have about 10 different controllers and in majority of them I @Autowire same services, So my question is this ok or not?

Is is ok to use @Autowire as many times as I need or will bring too much memory usage? Will it have some other effects on my application?

I use Spring 4.0 + hibernate JPA

Bhushan Bhangale

There is no problem with @Autowired.

Autowired finds the bean in Spring context and assign to the variable. It is just referencing to the same object of Service/Dao bean. It will not create duplicate.

But having so many objects injected to one class is a sign of one class doing a lot. Check possibility of refactoring the class into multiple classes wherever possible.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How many times is video transferring using Chromecast?

From Dev

How many times can a word be created using the input string?

From Dev

Count how many times button is clicked without using global variable

From Dev

how to count how many times a string occurs in a column using pandas

From Dev

Why do I have to click many times when using useRoute()?

From Dev

Counting how many times a character is typed without using string

From Dev

Using getDerivedStateFromProps to fetch API data is causing the component to render many times

From Dev

How to count how many times a number was printed using python?

From Dev

Entity-framework code is slow when using Include() many times

From Dev

Better way using an IDisposable object many times in a class

From Dev

finding how many times a sequence repeats in a data frame using python

From Dev

Function is getting called many times by using template interpolation?

From Dev

Is there a way to run one job many times using GNU parallel?

From Dev

Count how many times the app is open using shared preferences

From Dev

After using If statement in Custom filter the page being redirected many times

From Dev

Using user input to determine how many times a for loop iterates

From Dev

Count how many times values has changed in column using R

From Dev

Android firestore using "whereTo()" many times causes cost a lot?

From Dev

ERROR: localhost redirected you too many times USING PHP

From Dev

Slider slides many times

From Dev

Regex to match many times

From Dev

How to not repeat == many times

From Dev

Undo many times in Vim?

From Dev

SetState called many times

From Dev

filter many times a tibble

From Java

Using @Spy and @Autowired together

From Dev

Using @Autowired with AspectJ and Springboot

From Dev

How to find how many times the first letter is repeated in a string using Python?

From Java

Thread executes too many times and causes race condition even though I'm using locks

Related Related

  1. 1

    How many times is video transferring using Chromecast?

  2. 2

    How many times can a word be created using the input string?

  3. 3

    Count how many times button is clicked without using global variable

  4. 4

    how to count how many times a string occurs in a column using pandas

  5. 5

    Why do I have to click many times when using useRoute()?

  6. 6

    Counting how many times a character is typed without using string

  7. 7

    Using getDerivedStateFromProps to fetch API data is causing the component to render many times

  8. 8

    How to count how many times a number was printed using python?

  9. 9

    Entity-framework code is slow when using Include() many times

  10. 10

    Better way using an IDisposable object many times in a class

  11. 11

    finding how many times a sequence repeats in a data frame using python

  12. 12

    Function is getting called many times by using template interpolation?

  13. 13

    Is there a way to run one job many times using GNU parallel?

  14. 14

    Count how many times the app is open using shared preferences

  15. 15

    After using If statement in Custom filter the page being redirected many times

  16. 16

    Using user input to determine how many times a for loop iterates

  17. 17

    Count how many times values has changed in column using R

  18. 18

    Android firestore using "whereTo()" many times causes cost a lot?

  19. 19

    ERROR: localhost redirected you too many times USING PHP

  20. 20

    Slider slides many times

  21. 21

    Regex to match many times

  22. 22

    How to not repeat == many times

  23. 23

    Undo many times in Vim?

  24. 24

    SetState called many times

  25. 25

    filter many times a tibble

  26. 26

    Using @Spy and @Autowired together

  27. 27

    Using @Autowired with AspectJ and Springboot

  28. 28

    How to find how many times the first letter is repeated in a string using Python?

  29. 29

    Thread executes too many times and causes race condition even though I'm using locks

HotTag

Archive