2012-06-04 20 views
4

我使用spring java configs來創建一個web應用程序。spring java配置問題:拒絕的bean名稱'requestMappingHandlerMapping':沒有標識的URL路徑

當我在Tomcat上運行它說,資源/ MYAPP/MYAPP沒有找到

在控制檯輸出我注意到以下。我不確定這是否導致任何問題。

我只顯示那些奇怪的日誌行。作爲日誌這麼大

INFO: validateJarFile(C:\libraries\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myapp\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class 


Creating instance of bean 'beanNameHandlerMapping' 
Returning cached instance of singleton bean 'delegatingWebMvcConfiguration' 
Eagerly caching bean 'beanNameHandlerMapping' to allow for resolving potential circular  references 
Looking for URL mappings in application context: Root WebApplicationContext: startup date [Mon J  un 04 13:28:33 EDT 2012]; root of context hierarchy 
Rejected bean name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': no URL paths identified 
Rejected bean name 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor': no URL paths identified 
Rejected bean name 'org.springframework.context.annotation.internalRequiredAnnotationProcessor': no URL paths identified 
Rejected bean name 'org.springframework.context.annotation.internalCommonAnnotationProcessor': no URL paths identified 
Rejected bean name 'webAppContextConfig': no URL paths identified 
Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0': no URL paths identified 
Rejected bean name 'delegatingWebMvcConfiguration': no URL paths identified 
Rejected bean name 'requestMappingHandlerMapping': no URL paths identified 
Rejected bean name 'viewControllerHandlerMapping': no URL paths identified 
Rejected bean name 'beanNameHandlerMapping': no URL paths identified 
Rejected bean name 'resourceHandlerMapping': no URL paths identified 
Rejected bean name 'defaultServletHandlerMapping': no URL paths identified 
Rejected bean name 'requestMappingHandlerAdapter': no URL paths identified 
Rejected bean name 'mvcConversionService': no URL paths identified 
Rejected bean name 'mvcValidator': no URL paths identified 
Rejected bean name 'httpRequestHandlerAdapter': no URL paths identified 
Rejected bean name 'simpleControllerHandlerAdapter': no URL paths identified 
Rejected bean name 'handlerExceptionResolver': no URL paths identified 
Rejected bean name 'configureInternalResourceViewResolver': no URL paths identified 
Rejected bean name 'environment': no URL paths identified 
Rejected bean name 'systemProperties': no URL paths identified 
Rejected bean name 'systemEnvironment': no URL paths identified 
Rejected bean name 'servletContext': no URL paths identified 
Rejected bean name 'contextParameters': no URL paths identified 
Rejected bean name 'contextAttributes': no URL paths identified 
Rejected bean name 'importRegistry': no URL paths identified 
Rejected bean name 'messageSource': no URL paths identified 
Rejected bean name 'applicationEventMulticaster': no URL paths identified 
Finished creating instance of bean 'beanNameHandlerMapping' 
Creating shared instance of singleton bean 'resourceHandlerMapping' 
Creating instance of bean 'resourceHandlerMapping' 
Returning cached instance of singleton bean 'delegatingWebMvcConfiguration' 
Eagerly caching bean 'resourceHandlerMapping' to allow for resolving potential circular references 
Mapped URL path [/css/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
Mapped URL path [/scripts/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
Mapped URL path [/images/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
Finished creating instance of bean 'resourceHandlerMapping' 

這裏是WebAppContextConfig.java

package com.example; 

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
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; 

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = "com.example") 
public class WebAppContextConfig extends WebMvcConfigurerAdapter{ 
//Resolve logical view names to .jsp resources in /WEB-INF/views directory 

@Bean 
public InternalResourceViewResolver configureInternalResourceViewResolver() { 
    InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 
    resolver.setPrefix("WEB-INF/jsp/"); 
    resolver.setSuffix(".jsp"); 
    return resolver; 
} 

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

這裏是WebAppInitializer.java

package com.example; 

import javax.servlet.ServletContext; 
import javax.servlet.ServletException; 
import javax.servlet.ServletRegistration; 

import org.springframework.context.annotation.ComponentScan; 
import org.springframework.web.WebApplicationInitializer; 
import org.springframework.web.context.ContextLoaderListener; 
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 
import org.springframework.web.servlet.DispatcherServlet; 
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; 

public class WebAppInitializer implements WebApplicationInitializer { 

/* (non-Javadoc) 
* @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext) 
*/ 
@Override 
public void onStartup(ServletContext servletContext) throws ServletException { 
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); 
    rootContext.register(WebAppContextConfig.class); 
    servletContext.addListener(new ContextLoaderListener(rootContext)); 

     AnnotationConfigWebApplicationContext dispatcherContext = 
       new AnnotationConfigWebApplicationContext(); 
       dispatcherContext.register(WebAppContextConfig.class); 

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); 
    dispatcher.setLoadOnStartup(1); 
    dispatcher.addMapping("/"); 


    DefaultServletHandlerConfigurer defaultConfig = new DefaultServletHandlerConfigurer(servletContext); 
    defaultConfig.enable(); 

} 

} 

也有基於任何好地方查找Java春天mvc配置?

感謝

+1

@ravi是來自/ myapp/myapp的請求,你是否明確地調用它,是你的上下文名稱myapp和映射myapp的控制器方法,請你確認一下 –

+0

@Biju我的項目名稱是myapp 。在webapp文件夾中,我有index.jsp,它轉發給myapp.jsp,並在控制器中映射到/ myapp。 – javaMan

回答

2

這不是根本原因@ravi,但我看到,我想強調,開始有幾個問題:

一個。您似乎通過ContextLoaderListener和Dispatcher servlet兩次加載Spring Java Config文件,只通過ContextLoaderListener執行它,您可以用這種方式定義您的DispatcherServlet - 只需加載一個空的上下文(理想情況下有兩個java配置 - 一個用於核心應用,另一個用於網絡配置):

ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new GenericWebApplicationContext()); 
dispatcher.setLoadOnStartup(1); 
dispatcher.addMapping("/"); 

b。你可以用log4j啓用調試模式,看看還有什麼記錄 - 如果沒有足夠的信息,請在跟蹤級別登錄。

c。內部視圖解析器路徑看起來有點不對勁 - 你缺少前進「/」:

resolver.setPrefix("/WEB-INF/jsp/"); 

能否請您嘗試以下,看看你現在看到什麼。

+0

當我讀取小於7.0的版本時,我更改了tomcat版本.'4有添加映射(「/」)的錯誤。我做出了您指出的更改以及一些更改。最後工作。但我仍然看到拒絕bean的東西。我不明白爲什麼會這樣 – javaMan