在Spring使用扫描组件的时候
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
这两行不要忘记了,这个问题IDEA看不出来,但是运行的时候会报错:
in XML document from class path resource [applicationContext.xml] is invalid
这个时候就是头文件的问题
将那两行加上就行了
完整代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.helloSpringMVC">
</context:component-scan>
</beans>