Weblogic 12没有web.xml webapp

时间:2016-02-03 21:28:30

标签: weblogic spring-4

是否可以创建没有web.xml的Spring Web Mvc应用程序[已在TOMCAT 8中成功完成并部署]并部署Weblogic 12.

步骤: 1)使用maven-archetype-webapp。 2)删除生成的web.xml和index.html。 3)下面是java配置文件:

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 {
}

/ **** ***** THIRD /

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/");
    }
}

2 个答案:

答案 0 :(得分:2)

在解决WebApplicationInitializer子类时,weblogic中存在一个错误。如果将冗余接口WebApplicationInitializer添加到TestConfig,它应该可以工作。

所以你的TestConfig应该是这样的..

public class TestInitializer extends AbstractAnnotationConfigDispatcherServletInitializer implements WebApplicationInitializer {
...... your code ....
}

答案 1 :(得分:0)

应该是可行的。

web.xml是2.5必需的,3.0 + 3.0不是必需的(可选)。

如果它在Tomcat中有效,那么它将在WLS(Web容器)

中工作