The first question
java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer
The main reason for this is that javax.servlet-api treats the spring container as a servlet container during runtime and causes a type conversion error.
Solution:
Modify the scope of javax.servlet-api in the pom.xml file to provide
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
The second question:
Could not resolve bean definition resource pattern [classpath:spring/applicationContext-*.xml]
In the SSM project, since there are mapper mapping files and some other configuration files, they need to be recognized in the maven project, so a configuration will be added to allow these static files to pass through.
<resources> <!-- If the mapper.xml file of this node is not added, it will be missed. --> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource>
However, the above configuration changes the default resource directory, resulting in all files in src/main/resources that cannot be scanned, which causes other files in the resources directory to be scanned. Therefore, the default resources directory configuration needs to be added:
<build> <resources> <!-- If the mapper.xml file of this node is not added, it will be missed. --> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </build>
The above article solves the problem of errors in maven launching Spring project is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.