基于weblogic的springjava配置
我目前是Spring的新手,我正在尝试学习它的纯java配置元素 我可以使用以下类在Tomcat上运行Spring应用程序: 配置类:基于weblogic的springjava配置,java,spring,spring-mvc,weblogic12c,Java,Spring,Spring Mvc,Weblogic12c,我目前是Spring的新手,我正在尝试学习它的纯java配置元素 我可以使用以下类在Tomcat上运行Spring应用程序: 配置类: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.inka.spring.test.maven.configuration;
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.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
/**
*
* @author User
*/
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.inka.spring.test.maven")
public class HelloWorldConfiguration extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
初始值设定项类:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.inka.spring.test.maven.configuration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
/**
*
* @author User
*/
public class HelloWorldInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] {HelloWorldConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}
这将调用一个.jsp页面,该页面根据我在上述代码中输入的路径打印相应的消息
但是,当我尝试使用weblogic时,它不起作用。我得到的只是403和404的错误
我本来会坚持使用Tomcat,但我们在组织中使用weblogic,我被指示构建我的应用程序来使用weblogic
请问,我应该在weblogic上使用一些额外的配置吗?好的,我终于解决了这个问题。事实证明,在初始值设定项类中,无论扩展哪个类,如果要在weblogic上部署,都必须始终实现WebApplicationInitializer类。对于Tomcat,您不必这样做(不知道JBoss和其他内容),但是对于weblogic,您必须实现该类 因此,在改变这一点之后:
public class HelloWorldInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
为此:
public class HelloWorldInitializer extends AbstractAnnotationConfigDispatcherServletInitializer implements WebApplicationInitializer {
一切正常
欲了解更多信息,请访问。也许您的URL写错了;你检查过所有日志了吗?spring上下文加载是否正确?您是否使用了正确的web应用程序上下文?URL是正确的:“localhost:7001/app name/”。日志没有显示任何活动,就好像应用程序只是一个正常的空web应用程序一样。SpringJava配置没有web.xml用法。您是否也向项目中添加了任何weblogic.xml?
public class HelloWorldInitializer extends AbstractAnnotationConfigDispatcherServletInitializer implements WebApplicationInitializer {