0

Hi I have over 30 controllers in My Spring Rest application and every controller is in a separate package.

├───account
│      AccountController.java
│
├───commons
│       AbstractController.java
│
├───offering
│       OfferingController.java
│
│
├───payment
│       PaymentController.java
│
├───paymentProfiles
│       ProfileController.java
│
├───product
│       ProductController.java
│
│
├───publication
│       PublicationController.java
│
│
├───transaction
│       TransactionController.java

Is it a good idea to make a new package controllers and put all of them in this location will this increase Spring Package Scanning.

Xelian
  • 16,680
  • 25
  • 99
  • 152
  • But is it a good practice in my case? – Xelian Jul 06 '15 at 15:31
  • When you think about it it's the [exact *opposite* of what makes sense](https://twitter.com/jessitron/status/578894315277000705). Interesting read: http://olivergierke.de/2013/01/whoops-where-did-my-architecture-go/ and – kryger Jul 07 '15 at 08:41

1 Answers1

1

Your question is clearly addressed by Effective Java Item 55: Optimize Judiciously. Most pointedly, Mr Blog says:

Don’t sacrifice sound architectural principles for performance. Strive to write good programs rather than fast ones

Your endeavored optimization will only yield a couple of milliseconds if any and that at loading time (where it is less valuable).

Structure your packages with structural consideration rather than performance considerations. If you are looking for best practices, apply generic package organisation practices like these.

Community
  • 1
  • 1
Fritz Duchardt
  • 11,026
  • 4
  • 41
  • 60
  • OK if a have sub packages and another classes put all in one package is obvious bad idea. But in my case I think even when they are in one package they can be found easier in visually. I do not want to put them together only because of the easier found. So I am searching another evidence but obliviously performance is not the one. – Xelian Jul 06 '15 at 17:28
  • 1
    @Xelian I personally agree with the notion to stick all Controllers together in some web package and have seen a similar practice in several projects, but of course this depends on the overall size and structure of your app. – Fritz Duchardt Jul 07 '15 at 08:04
  • @CodeRunner Ok but I suppose that in the future the number of controllers will increase to 40-50. – Xelian Jul 07 '15 at 09:24
  • 1
    @Xelian Sounds like way to many classes for a single package especially based on the assumption that those Controllers are quite diverse functionality-wise. – Fritz Duchardt Jul 07 '15 at 11:52