IDEA,搭建spring+maven多模块,启动报错
我使用IDEA搭建spring+maven多模块项目,实现一个最简单的hello world,现在启动报错了:
The requested resource (/) is not available。
项目目录结构如下:
![图片上传中...]
web.xml代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>com.jd-web</display-name>
<!-- 加载springMVC配置 -->
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring-config.xml代码
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-autowire="byName">
<bean class="com.jd.spring.task.common.spring.ApplicationContextUtil"/>
<!-- 注解扫描包 -->
<context:component-scan base-package="com.jd.spring.task.web" />
<!-- 导入分类配置 -->
<import resource="classpath*:spring/spring-config-mvc.xml"/>
<import resource="classpath*:spring/spring-config-work.xml"/>
</beans>
spring-config-mvc.xml
<?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" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
default-autowire="byName">
<!-- 添加MVC注解模式 -->
<mvc:annotation-driven/>
<!-- 映射静态资源 -->
<mvc:resources location="/WEB-INF/statics/" mapping="/resource/**"/>
<!-- 加载属性文件 -->
<bean class="com.jd.spring.task.common.spring.CustomizedPropertyConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
<!-- 视图解析器配置 -->
<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/vm/" />
<property name="configLocation" value="classpath:velocity.properties" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix" value=".vm" />
<property name="contentType" value="text/html;charset=UTF-8" />
</bean>
<!-- 文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
</bean>
</beans>
IndexController.java
@Controller
@RequestMapping("/")
public class IndexController {
@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
@Authentication(type = AuthType.PUBLIC)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
return "hello";
}
}
但是工程中有IndexController,工程启动起来后应该调用IndexController中的方法:
@Controller
@RequestMapping("/")
public class IndexController {
@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
@Authentication(type = AuthType.PUBLIC)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
return "hello";
}
}
但是为什么报资源找不到?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)