spring-mvc 配置文件

<?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:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.2.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd 
        http://www.springframework.org/schema/task 
        http://www.springframework.org/schema/task/spring-task-4.2.xsd">  
    
    <context:component-scan base-package="gold.core"/>
    
    <import resource="classpath:spring-tx.xml"/>
    
    <mvc:annotation-driven>
        <!-- 处理responseBody中文乱码 -->
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes" value="text/plain;charset=UTF-8" />
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    
    <!-- 定时器 -->
    <task:scheduled-tasks>
        <task:scheduled ref="catalogScanTask" method="timerJob" cron="0/5 * * * * ?"/>
    </task:scheduled-tasks>
    
</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring MVC 是一个用于构建 Web 应用程序的框架,它基于 Spring 框架之上,提供了一套强大的处理请求、响应和视图的机制。下面是一个简单的 Spring MVC 配置示例: 1. 首先,你需要在 pom.xml 文件中添加 Spring MVC 相关的依赖项: ```xml <dependencies> <!-- Spring MVC --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.9</version> </dependency> <!-- 其他依赖项 --> </dependencies> ``` 2. 创建一个配置类(例如 `WebConfig.java`),并配置 Spring MVC: ```java @Configuration @EnableWebMvc @ComponentScan(basePackages = "com.example.controller") // 指定控制器所在的包路径 public class WebConfig implements WebMvcConfigurer { @Override public void configureViewResolvers(ViewResolverRegistry registry) { registry.jsp("/WEB-INF/views/", ".jsp"); // 配置 JSP 视图解析器 } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**") .addResourceLocations("/static/"); // 配置静态资源访问路径 } } ``` 3. 创建一个控制器类(例如 `HelloController.java`): ```java @Controller public class HelloController { @RequestMapping("/") public String hello() { return "hello"; // 返回视图名称 } } ``` 4. 创建一个 JSP 视图文件(例如 `hello.jsp`): ```jsp <html> <body> <h1>Hello, Spring MVC!</h1> </body> </html> ``` 以上是一个简单的 Spring MVC 配置示例,你可以根据自己的需求进行进一步的配置和扩展。希望可以帮助到你!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值