-2

I have tried my every possible ways of adding class in different packages such as application class in package com.packagename and my controller in different package named model and when i try to execute the program it returns the default white label error and when i put the classes in the same package it runs successfully.

So i wanted to ask if there is any problem with the project or i need to give any path. Before I have also tried notations that says component scan and all but that to did not came handy

enter image description here

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • your `@SpringBootApplication` annotated class must be in the root package in order to avoid additional configuration about which packages need to be scanned. https://stackoverflow.com/questions/33619532/configuration-using-annotation-springbootapplication – Michael Kreutz May 10 '20 at 19:08
  • @MichaelKreutz i was just curious if u can elaborate a bit more regarding the root package. – Sundaram Mishra May 10 '20 at 19:31
  • you could consider `com.boltforever.moviecatalog` as your root package where you put your `@SpringBootApplication` annotated class and then create sub-packages `service`, `model`, `repository`, ... relative to this one. So you would have to rename `moviecatalogservices` into `moviecatalog`, then move `model` and `resources` into it and create package `service` in it. – Michael Kreutz May 10 '20 at 19:37
  • @MichaelKreutz thanx for taking your time but i did that also but the result was the same and it return the fallback again and again in different sub packages that consist in root package – Sundaram Mishra May 10 '20 at 20:08

2 Answers2

1

Let's say your main class(which is annotated with @SpringBootApplication) is in the package "com.somepackage", then try putting your controller in "com.somepackage.controller"(It is recommended that other classes are placed in the subpackage of your main class). with this change it should work.

SAS DEV
  • 70
  • 3
  • Actually i am using spring initializr for generating the project and i have to give name accordingly to the artifact and groupid so that are generated by default and in that i am trying to add another package but its failing to do the same, – Sundaram Mishra May 11 '20 at 05:39
1

You put your classes in wrong places and your package are very messy. You should have a structure like this

--src
    main
      java
        com.boltforever.moviecatalog
                                model
                                service
                                    MyService.java
                                controller
                                    MyController.java
                                MovieCatalogServiceApplication.java

And this should work

Kamiel Ahmadpour
  • 1,215
  • 12
  • 16
  • Well thanx for the effort put in the scenario but its failing to do the same and i am using spring initializr for that purpose and importing the same so they are generated by default and package name can be refactored but same problem comes. – Sundaram Mishra May 11 '20 at 05:41