java – Servlet.init() for servlet [dispatcher] threw exception
java – Servlet.init() for servlet [dispatcher] threw exception
the root of problem is here:
Failed to introspect bean class
[com.apurv.onlineshopping.controller.PageController] for resource
metadata: could not find class that it depends on
DI container cant find the class defined in another .jar
to solve the problem lets go through the code:
you inject a DAO component:
@Controller
public class PageController {
@Autowired
private CategoryDAO categoryDao;
which can be found by in packges (not .jars) defined in web.xml:
<context:component-scan base-package=com.apurv.onlineshopping.controller/>
<context:component-scan base-package=com.apurv.shoppingbackend.daoImpl />
as I found your two modules disposited alone, so build system have no information where them can found dependency for onlineshopping until you instruact them by hand.
My solution is: to organize your two independend modules into parent-modules pom:
here id parent pom.xml:
<?xml version=1.0 encoding=UTF-8?>
<project ...
<groupId>com.apurv</groupId>
<artifactId>so</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>shoppingbackend</module>
<module>onlineshopping</module>
</modules>
</project>
next put a ref to parent in your modules:
onlineshoppings pom.xml
<project ...
<modelVersion>4.0.0</modelVersion>
<!--unnecessary <groupId>com.apurv</groupId>-->
<artifactId>onlineshopping</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>onlineshopping</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.apurv</groupId>
<artifactId>so</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
... tail of your code is unchanged ...
and shoppingbackends pom.xml
<project ...
<modelVersion>4.0.0</modelVersion>
<!--unnecessary <groupId>com.apurv</groupId>-->
<artifactId>shoppingbackend</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>shoppingbackend</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.apurv</groupId>
<artifactId>so</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
... tail of your code is unchanged ...
Next build root module:
mvn package
Rest of your code is unchanged, you can found full repo rehe: https://github.com/enginetag/so-apurv