Как использовать @Import и @ComponentScan в SpringMvcCONfigJAVA

Программисты JAVA общаются здесь
Ответить
Гость
 Как использовать @Import и @ComponentScan в SpringMvcCONfig

Сообщение Гость »

`сейчас,Я пытаюсь импортировать SpringMvcSupport, расширяющий WebMvcConfigurationSupport в @Configuration

Код: Выделить всё

@ComponentScan({"com.itheima.controller"})
@EnableWebMvc
public class SpringMvcConfig {
}
there are two plans,but one worked,I want  to know the resaon
First one:
`@Configuration
@ComponentScan({"com.itheima.controller","com.itheima.config"})
@EnableWebMvc
public class SpringMvcConfig {
}`

`@Configuration
`public class SpringMvcSupport extends WebMvcConf

urationSupport {
//设置静态资源访问过滤,当前类需要设置为配置类,并被扫描加载
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
//当访问/pages/????时候,从/pages目录下查找内容
registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
registry.addResourceHandler("/js/**").addResourceLocations("/js/");
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");
}
}``
Работает;
Второй:

Код: Выделить всё

`    @Configuration
@ComponentScan({"com.itheima.controller"})
@EnableWebMvc
@Import(SpringMvcSupport.class)
public class SpringMvcConfig {
}`
`public class SpringMvcSupport extends WebMvcConfigurationSupport {
//设置静态资源访问过滤,当前类需要设置为配置类,并被扫描加载
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
//当访问/pages/????时候,从/pages目录下查找内容
registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
registry.addResourceHandler("/js/**").addResourceLocations("/js/");
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");
}
}`
ошибка: НЕТ сопоставления для ***.html
Я хочу знать, почему, я здесь новенький`

Подробнее здесь: https://stackoverflow.com/questions/781 ... gmvcconfig
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»