Недавно я планировал учиться java и jsp. Поэтому я установил eclipse 2019-12, jdk 1.8 и tomcat 8.5.55. И я создал динамическое c веб-приложение и преобразовал его в проект Maven. После всех этих работ структура моего проекта выглядит следующим образом.
Структура моего приложения:
Раздуто от счастья, я составил едва ли мой java исходник и скомпилировал через компилятор mvn. Это нормально. Но когда я запустил «Запуск на сервере», я обнаружил, что мои javascript файлы включены, а мои css - нет. Я попробовал это по-другому, но безрезультатно. Почему эти явления произошли только у меня?
Мой конфиг источник:
package net.enagape.weblog.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.util.pattern.PathPattern;
@Configuration
@EnableWebMvc
@ComponentScan("net.enagape.weblog")
public class WebMvcConfig implements WebMvcConfigurer {
@Bean(name = "viewResolver")
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations(
"/META-INF/resources/", "/resources/", "/assets/"
);
// Add css Assets.
registry.addResourceHandler("/css/**").addResourceLocations(
"/css/"
);
// Add js Assets.
/*registry.addResourceHandler("/js/**").addResourceLocations(
"classpath:/resources/js/"
);*/
// Add WebJars for Bootstrap & jQuery
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/"
);
}
}
}