Issue
Am new to spring boot unable to get the issue resolved. In below Screenshots i have commented "/hello" which i could access with localhost:1200/hello .But unable to access other controllers as "/welcome" ,"/home" attached screenshots .
Solution
Since your @SpringBootApplication
annotation is in com.example.demo
, and no basePackage is defined for scanning, it will only scan that package and its nested packages. The easiest way to solve this is to move your controller package.
From this:
.
└── main
├── java
│ └── com
│ └── example
│ ├── controller
│ │ └── DemoRestController.java
│ └── demo
│ └── DemoApplication.java
└── resources
└── application.properties
To this:
.
└── main
├── java
│ └── com
│ └── example
│ └── demo
│ ├── controller
│ │ └── DemoRestController.java
│ └── DemoApplication.java
└── resources
└── application.properties
Doc from @ComponentScan
:
Either basePackageClasses() or basePackages() (or its alias value()) may be specified to define specific packages to scan. If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.
Answered By - Pär Nilsson