我正在开发一个弹簧支架控制器。但是,当我尝试访问 url ( http://localhost:8080/customer-crm/api/customer ) 时,它不起作用并给出 404 not find 。但对于根“/”,它工作正常并给出index.jsp
页面
这是AppConfiguration.class
:
package com.customer.crm.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.customer.crm")
public class AppConfiguration {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
这是Index.class控制器:
package com.customer.crm.rest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.customer.crm.entity.Customer;
@RestController
@RequestMapping("/api")
public class Index {
@RequestMapping(value = "/customer", method = RequestMethod.GET)
public Customer getIndex() {
System.out.println("executing in index controller");
Customer customer = new Customer("Mike", "John", "mike.john@gmail.com");
return customer;
}
甚至连消息也getIndex()
没有打印出来。我尝试清理项目并清理 tomcat 目录,但没有任何改变。谁能告诉我问题出在哪里?
千万里不及你
相关分类