简体   繁体   中英

Spring mvc + Maven multi module + Ear - deployment

I created a following multi module project with Spring + Maven. It has following hierarchy,

在此处输入图片说明

When I build this project I am getting cleverEE.ear file under clevermoe_EE/target . This ear file contains the following things,

在此处输入图片说明

Initially I used JBoss7.1.1 AS to deployment, So I copied this ear file to JBoss depolyments, I am able to load the war as follows,

http://localhost:8080/clevermoe_web

I followed this link to make spring project, http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example-annotation/

So I used the following classes in clevermoe_web module,

SpringWebConfig,

@EnableWebMvc // mvc:annotation-driven
@Configuration
@ComponentScan({ "com.zeptoh.clever.controllers" })
public class SpringWebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations(
                "/resources/");
    }

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/views/jsp/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

MyWebInitializer class,

public class MyWebInitializer extends
        AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        // TODO Auto-generated method stub
        return new Class[] { SpringWebConfig.class };
    }

    @Override
    protected String[] getServletMappings() {
        // TODO Auto-generated method stub
        return new String[] { "/" };
    }

}

Controller class,

@Controller
public class HelloController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Clever Portal");
        return "hello";
    }

    @RequestMapping(value = "/hello/{name:.+}", method = RequestMethod.GET)
    public ModelAndView hello(@PathVariable("name") String name) {
        ModelAndView model = new ModelAndView();
        model.setViewName("hello");
        model.addObject("msg", name);
        return model;
    }

}

I cant open spring controller as follows,

http://localhost:8080/clevermoe_web/hello/something

It says 404 error

HTTP Status 404 - /clevermoe_web/hello/something

type Status report

message /clevermoe_web/hello/something

description The requested resource (/clevermoe_web/hello/something) is not available.

JBossWeb/2.0.1.GA

I read some articles, which says, to access ear deployment, it is not good move to use JBoss. So I downloaded TomEE server. It extracts the ear file to a folder. But I met the same problem what I had in JBoss.

I copied the war file(clevermoe_web.war) inside the cleverEE.ear in TomEE server's webapps folder, it works fine to access the spring controller.

I copied the war file(clevermoe_web.war) inside the cleverEE.ear in JBoss, But still it shows 404 error.

Can someone say what I need to take care of here?

Does http://localhost:8080/clevermoe_web-0.1/hello/something works? if you don't map the war context in application.xml in META-INF this is the context used (from the war name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM