java—在weblogic 12.1.3中发布包含SpringREST服务的ear

xzv2uavs  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(251)

我构建了一个小项目,使用springframework提供rest服务。问题是在将这个ear发布到weblogic服务器之后,在ear中访问这个项目。
当我在weblogic中将这个项目作为一个独立的war发布时,一切都很好地结束了,当服务器启动时,我的springwebappinitializer会按预期加载,我可以使用地址访问webservicelocalhost:7001/internal-webservices/project/12. 但是当我把这个war添加到ear中时,springwebappinitializer永远不会被调用。
有什么想法吗?
我的一些配置:
pom.xml文件:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.3.1.RELEASE</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.3.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.3.1.RELEASE</version>
</dependency>
<dependency>

我的applicationcontextconfig类:

@Configuration
@EnableWebMvc
@ComponentScan("my_package.*")
public class ApplicationContextConfig {
// No need ViewSolver
// Other declarations if needed ...      
}

我的webapplicationinitializer:

public class SpringWebAppInitializer  implements WebApplicationInitializer{

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
        appContext.register(ApplicationContextConfig.class);

        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("internal-webservices",
                new DispatcherServlet(appContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");

        // UTF8 Charactor Filter.
        FilterRegistration.Dynamic fr = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class);

        fr.setInitParameter("encoding", "UTF-8");
        fr.setInitParameter("forceEncoding", "true");
        fr.addMappingForUrlPatterns(null, true, "/*");
    }

}

还有,我的restcontroller类:

@RestController
public class ProjectController {

       @RequestMapping(value = "/project/{id}", method = RequestMethod.GET,
 produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
    public List<String> getProject(@PathVariable("id") String id) {
        List<String> result = new ArrayList<String>();
        result.add("id: "+ id);
        return result;
    }
}

你好,菲利佩

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题