Можно ли создать Spring Web App Mvc без web.xml [уже сделано и успешно развернуть в TOMCAT 8] и развертывания WebLogic 12.Weblogic 12, без web.xml веб-приложение
шаги: 1) Использовано Maven-архетип-веб-приложение. 2) Удалены сгенерированные web.xml и index.html. 3) Ниже приведены ява конфигурационные файлы:
package com.test.xyz.config;
import javax.servlet.Filter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class TestInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { RootConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
protected Filter[] getServletFilters() {
Filter [] singleton = { new CORSFilter() };
return singleton;
}
}
/** Второй *****/
package com.test.xyz.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@ComponentScan(basePackages={"com.test.xyz"},
excludeFilters={
@Filter(type=FilterType.ANNOTATION, value=EnableWebMvc.class)
})
public class RootConfig {
}
/**** ТРЕТИЙ *****/
package com.test.xyz.config;
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.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
/**
* All the beans configured here will be loaded under dispatcher-servlet
* application context
*/
@Configuration
/**
* @EnableWebMvc is replacement for <mvc:annotation-driven>
*/
@EnableWebMvc
@ComponentScan("com.test.xyz")
public class WebConfig extends WebMvcConfigurerAdapter{
/**
* @config JSP view resolver
*/
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver =
new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
/**
* @handle request for static resources
* otherwise dispatcher-servlet need to do it
* here you are forwarding request to servlet container’s
* default servlet
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/standardversion/**").addResourceLocations("/standardversion/");
}
}
Не работает после того, как я добавил web.xml в одном проекте, он начал придумывать. Раньше он выдавал - HTTP 403 «Запрещено». Я добавил шаги, которые я использовал выше. Пожалуйста, дайте мне знать, если я ничего не пропущу. – AVI