1
我已經使用html創建了Spring引導應用程序,但出現錯誤 「未找到具有URI的HTTP請求的映射[/app.js在名爲 '的DispatcherServlet'找不到具有名稱爲'dispatcherServlet'的DispatcherServlet中具有URI [/app.js]的HTTP請求的映射
項目結構的DispatcherServlet:
TeamTrack
--Src
--Main
--java
--com.tm.controller
--application
--CertificateController
--WebConfig
--resources
---static
--app.js
--Test
Application.java:
@SpringBootApplication
@EnableAutoConfiguration
@EntityScan("com.tm.vo")
@EnableJpaRepositories("com.tm.repository")
@EnableWebMvc
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Certif icateController.java
@EnableWebMvc
@Controller
public class CertificateController {
@Autowired
private certificateRepository certRep;
@RequestMapping(value = "/cert",method = RequestMethod.GET)
public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "certificate";
}
@RequestMapping(value = "/addCertificate", method = RequestMethod.POST)
public String addNewCertificate(@RequestParam String certName,@RequestParam String certProvider)
{
certificate cert =new certificate();
cert.setCertificateName(certName);
cert.setCertificateProvider(certProvider);
certRep.save(cert);
return "/";
}
}
WebConfig.java
@Configuration
@AutoConfigureAfter(DispatcherServletAutoConfiguration.class)
public class WebConfig extends WebMvcConfigurerAdapter {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/static/", "classpath:/static/css/", "classpath:/static/js/" };
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/static/**")) {
registry.addResourceHandler("/static/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
}
}
certificate.html
在certificate.html,只需調用Java腳本和它的角。
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="app.js"></script>
錯誤詳細信息:
No mapping found for HTTP request with URI [/app.js] in DispatcherServlet with name 'dispatcherServlet'
在Chrome中,在開發工具,得到這個錯誤:
Failed to load resource: the server responded with a status of 404()
任何人都可以在此幫助?
我已經添加了下面的代碼在Webconfig,但仍然得到錯誤。 @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)configurer.enable(); } – BaskarNatarajan
我錯過了certificate.html代碼,只是粘貼如下<!DOCTYPE HTML>
<體NG-控制器=」 PhoneListController 「>{{電話。段}}