Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC Created without xml working fine, adding webflow configuration not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC Created without xml working fine, adding webflow configuration not working

    I Configure withuot xml my MVC Context using Apache Tiles as View Resolver like this

    1) Create a config file that allow me to use jdbc called "configuracionContexto.java"
    Code:
    package config;
    
    import javax.sql.DataSource;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.datasource.DataSourceTransactionManager;
    import org.springframework.transaction.PlatformTransactionManager;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    @Configuration
    @EnableTransactionManagement
    @ComponentScan(basePackages = { "servicios",
    		"repositorio",
    		"dominio.soporte",
    		"config"
    		})
    public class ConfiguracionContextoInfraestructura {
    	
    	@Autowired
    	private DataSource BaseDeDatos;
    
    	@Bean  
    	public JdbcTemplate jdbcTemplate() {
    		return new JdbcTemplate(BaseDeDatos);
    	}
    	
    	@Bean
    	public PlatformTransactionManager transactionManager() {
    		return new DataSourceTransactionManager(BaseDeDatos);
    	}
    
    }
    2) The I create my webMVCContext in file calle "configuracionContextoWebMVC" with annotations too:
    Code:
    package web;
    
    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = { "web" })
    public class ConfiguracionContextoWebMvc extends WebMvcConfigurerAdapter{
    
    	
    	@Override
        public void addResourceHandlers(final ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/resources/**/*").addResourceLocations("classpath:/META-INF/web-resources/");
        }
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(localeChangeInterceptor());
        }
    	
    	//-- Start Locale Support (I18N) --//
    
        @Bean
        public HandlerInterceptor localeChangeInterceptor() {
            LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
            localeChangeInterceptor.setParamName("lang");
            return localeChangeInterceptor;
        }
    
        @Bean
        public LocaleResolver localeResolver() {
        	CookieLocaleResolver localeResolver = new CookieLocaleResolver();
        	localeResolver.setDefaultLocale(new Locale("es"));
            return localeResolver;
        }
    
        @Bean
        public MessageSource messageSource() {
            ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
            messageSource.setBasename("classpath:/messages");
            messageSource.setUseCodeAsDefaultMessage(true);
            return messageSource;
        }
    
        //-- End Locale Support (I18N) --//
    }
    3) Then I configure my view with tiles (add xml tiles definition) then a viewresolver like this:
    Code:
    package web.config;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.view.tiles2.TilesConfigurer;
    import org.springframework.web.servlet.view.tiles2.TilesViewResolver;
    
    @Configuration
    public class ConfiguracionVista {
    	@Bean
        public TilesConfigurer tilesConfigurer() {
            return new TilesConfigurer();
        }
    
        @Bean
        public TilesViewResolver tilesViewResolver() {
            TilesViewResolver tilesViewResolver = new TilesViewResolver();
            tilesViewResolver.setOrder(2);
            return tilesViewResolver;
        }
    	@Bean
    	public ViewResolver tilesViewResolver() {
    		UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
    		urlBasedViewResolver.setOrder(1);
    		urlBasedViewResolver.setViewClass(TilesView.class);
    		return urlBasedViewResolver;
    	}
    }
    4) Everythings works fine, but now I want to add webflow support, well I don't have a xml configuration file then I do this:


    a) Create a webflow-config
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:webflow="http://www.springframework.org/schema/webflow-config"
    	xsi:schemaLocation="
               http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
               http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd">
    
    	<webflow:flow-executor id="flowExecutor" />
    
    	<webflow:flow-registry id="flowRegistry"
    		base-path="/WEB-INF/views" flow-builder-services="flowBuilderServices">
    		<webflow:flow-location-pattern value="/**/*-flow.xml" />
    	</webflow:flow-registry>
    
    	<webflow:flow-builder-services id="flowBuilderServices"
    		view-factory-creator="mvcViewFactoryCreator" development="true" />
    
    	<bean id="mvcViewFactoryCreator"
    		class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    		<property name="viewResolvers">
    			<list>
    				<ref bean="tilesViewResolver" />
    			</list>
    		</property>
    	</bean>
    
    </beans>
    b) The I Add the FlowHandlerAdapter and FlowHandlerMapping Beans
    Code:
    package web.config;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.ImportResource;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
    import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
    import org.springframework.webflow.executor.FlowExecutor;
    import org.springframework.webflow.mvc.portlet.FlowHandlerAdapter;
    import org.springframework.webflow.mvc.servlet.FlowHandlerMapping;
    
    
    @Configuration
    @ImportResource("classpath:/spring/webflow-config.xml")
    public class ConfiguracionContextoWebFlow {
    
    	@Autowired
    	private FlowExecutor flowExecutor;
    	@Autowired
    	private FlowDefinitionRegistry flowRegistry;
    	@Autowired
    	private LocaleChangeInterceptor localeChangeInterceptor;
        
    	@Bean
    	public FlowHandlerAdapter flowHandlerAdapter() {
    		FlowHandlerAdapter flowHandlerAdapter = new FlowHandlerAdapter();
    		flowHandlerAdapter.setFlowExecutor(flowExecutor);
    		return flowHandlerAdapter;
    	}
    
    	@Bean
    	public FlowHandlerMapping flowHandlerMapping() {
    		FlowHandlerMapping flowHandlerMapping = new FlowHandlerMapping();
    		flowHandlerMapping.setInterceptors(new Object[] { localeChangeInterceptor() });
    		flowHandlerMapping.setFlowRegistry(flowRegistry);
    		return flowHandlerMapping;
    	}    
    	
    }
    c) Later I created a flow called: hellowebflow inside folder WEB-INF/views/pruebas pruebas-flow.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <flow xmlns="http://www.springframework.org/schema/webflow"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/webflow
            http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    
       <view-state id="hello" view="pruebas/helloworldflow">
            <transition on="next" to="helloend"/>
        </view-state>
       <end-state id="helloend" view="pruebas/helloworldflowend"/>
     </flow>
    d) two pages called helloworldflow.jsp and helloworldflowend.jsp at folder WEB-INF/views/pruebas:

    helloworldflow.jsp
    Code:
    <%@page isELIgnored="false"%>
    <html>
    <body>
    <h2>This is the first HelloWorldFlow! See the url!</h2>
    <a href="${flowExecutionUrl}&_eventId=next">Go to next page</a>
    </body>
    </html>
    helloworldflowend
    Code:
    <%@page isELIgnored="false"%>
    <html>
    <body>
    <h2>Hello World Flow ended!</h2>
    </body>
    </html>
    Then I called the flow by using http:

    http://localhost:8080/contexto/pruebas
    and then the following error is raised:
    HTTP Status 500 -

    type Exception report

    message

    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: No adapter for handler [[FlowHandlerMapping.DefaultFlowHandler@aa4243]]: Does your handler implement a supported interface like Controller?

    note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.
    GlassFish Server Open Source Edition 3.1.2.

    Then LOG Shows

    WARNING: StandardWrapperValve[dispatcher]: PWC1406: Servlet.service() for servlet dispatcher threw exception
    javax.servlet.ServletException: No adapter for handler [[FlowHandlerMapping.DefaultFlowHandler@aa4243]]: Does your handler implement a supported interface like Controller?

    What could be missing in my configuration?

    Thanks
    Last edited by xiul; Mar 28th, 2013, 08:27 AM. Reason: Updating to last version of working code that was failing with the same error

  • #2
    Solved but...

    I solved it today after wasting a lot of time :

    just change the imports of the class file ConfiguracionContextoWebFlow where FlowHandlerAdapter and FlowHandlerMapping Beans were created from THIS:
    Code:
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.ImportResource;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
    import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
    import org.springframework.webflow.executor.FlowExecutor;
    import org.springframework.webflow.mvc.portlet.FlowHandlerAdapter;
    import org.springframework.webflow.mvc.servlet.FlowHandlerMapping;
    TO THIS


    Code:
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.ImportResource;
    import org.springframework.web.servlet.DispatcherServlet;
    import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
    import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
    import org.springframework.webflow.executor.FlowExecutor;
    import org.springframework.webflow.mvc.servlet.FlowHandlerAdapter;
    import org.springframework.webflow.mvc.servlet.FlowHandlerMapping;
    I hope this can be useful to someone in the future.
    Bye.

    Comment

    Working...
    X