springmvc-springMVC4整合Tiles3的问题

问题描述

springMVC4整合Tiles3的问题

springMVC配置Tiles3,spring-mvc.xml的配置文件如下

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

    <!-- 配置自动扫描的包 -->
    <context:component-scan base-package="com.lhd"
        use-default-filters="true">
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
        <context:include-filter type="annotation"
            expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    </context:component-scan>

    <!-- 配置视图解析器 :如何把handler 方法返回值解析为实际的物理视图-->
    <bean id="view"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/jsps/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!--
        配置国际化资源文件 <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="i18n"/> </bean>
    -->

    <!-- 直接 配置目标页面 -->
    <!--
        可以直接响应转发的页面,不需要经过hendler <mvc:view-controller path="/success"
        view-name="success" />
    -->

    <mvc:default-servlet-handler />
    <!-- 在实际开发中通常都需配置 mvc:annotation-driven 标签 -->
    <mvc:annotation-driven></mvc:annotation-driven>

    <!-- 配置视图解析器       解析器:使用视图的名字来解析代码 -->
    <!-- 通过order属性值 来定义视图优先级,数值越小,解析器的优先级越高-->
    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
        <property name="order" value="100"></property>
    </bean>

    <!-- 定义tiles视图解析器-->
    <bean id="tilesViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.tiles3.TilesView</value>
        </property>
    </bean>

    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles/tiles.xml</value>
            </list>
        </property>
    </bean> 

</beans>

tiles.xml的配置如下

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>
    <!-- Default Main Template -->
    <definition name="base" template="/WEB-INF/jsps/main.jsp">
        <put-attribute name="tiles" value="........." type="string" />
        <put-attribute name="header" value="/WEB-INF/jsps/top.jsp" />
        <put-attribute name="menu" value="/WEB-INF/jsps/menu.jsp" />
        <put-attribute name="search" value="/WEB-INF/jsps/search.jsp" />
        <put-attribute name="body-left" value="/WEB-INF/jsps/left.jsp" />
        <put-attribute name="body" value="/WEB-INF/jsps/body.jsp" />
        <put-attribute name="footer" value="/WEB-INF/jsps/footer.jsp" />
    </definition>

    <definition name="userLists" extends="base">
        <put-attribute name="body" value="/jsps/user/goods/list.jsp" />
    </definition>

</tiles-definitions>

但是打开,会报 Attribute 'header' not found异常,
后用juni测试,其测试代码如下:

 public class TestCase {

    @Test
    public void test1(){
        String bean = "spring-mvc.xml";
        ApplicationContext context = new ClassPathXmlApplicationContext(bean);

        context.getBean("viewResolver");

    }
}

之后报了这个异常,各位大侠知道 是什么原因么,路径什么的都对过了,没有错,就是读取不到我的tiles.xml配置文件

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tilesConfigurer' defined in class path resource [spring-mvc.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.lhd.test.TestCase.test1(TestCase.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
    at org.apache.tiles.request.ApplicationAccess.register(ApplicationAccess.java:50)
    at org.apache.tiles.startup.AbstractTilesInitializer.initialize(AbstractTilesInitializer.java:62)
    at org.springframework.web.servlet.view.tiles3.TilesConfigurer.afterPropertiesSet(TilesConfigurer.java:271)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
    ... 36 more

解决方案

Zhe Program is not problem


时间: 2024-09-13 09:53:37

springmvc-springMVC4整合Tiles3的问题的相关文章

Spring+SpringMVC+MyBatis整合

1.基本概念 1.1.Spring         Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development and Design中阐述的部分理念和原型衍生而来.它是为了解决企业应用开发的复杂性而创建的.Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spring的用途不仅限于服务器端的开发.从简单性.可测试性和松耦合的角度而

springmvc+mybatis整合 MapperScannerConfigurer配置出错

问题描述 springmvc+mybatis整合 MapperScannerConfigurer配置出错 1C 配置如下: 问题:如果配置了 <property name=""sqlSessionFactoryBeanName"" value=""wechatSqlSessionFactory"" />,启动的时候报错如下:Caused by: org.springframework.beans.factory.B

springmvc+mybatis整合

问题描述 springmvc+mybatis整合 spring-servlet.xml <beans:bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"> <beans:property name="driverClassName" value="org.postgresql.Driver"/> <beans

MyBatis和SpringMVC的整合&amp;lt;mvc&amp;gt;标签报错分析

这几天在做MyBatis和SpringMVC的整合的时候,虽然已经在xml中引入了相关的命名空间和xsd,但是在使用<mvc:annotation-driven/>的时候eclipse仍然会报错,显示mvc的xsd文件不可读和找不到,网上都说是没有引入红框中的内容而导致报错的 ,但是经过检查自己的,已经是引入了的,还报错!如果大家也遇到了这种情况,可以使用下面的办法,自己也是在看遍百度上大大小小的问答后自己摸索出来的. 步骤: 1.找到自己下载的spring-framework-4.1.6.R

spring springmvc mybatis整合时,tomcat启动正常,查询数据库时报错

问题描述 spring springmvc mybatis整合时,tomcat启动正常,查询数据库时报错 Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YE

hibernate4-求助大神,spring.springMvc.hibernate整合。并且全是注解

问题描述 求助大神,spring.springMvc.hibernate整合.并且全是注解 实在找不到教程,望能提供和完整的教程,视频最好 解决方案 给你了你就跑了不采纳怎么办?所以如果需要教程,请先采纳下姐姐的回答,姐姐这就给你. 解决方案二: 慕课网上找找,还有csdn学院里面找找,传智播客的视频教程 找找总有的.现在网络资源这么丰富,勤快耐心点,学习资源还是一大堆的.祝好! 解决方案三: 这个从网上搜吧.去git 里面找个下载. 解决方案四: http://v.youku.com/v_sh

springmvc+hbrat整合出现这个错误,求大神帮帮忙

问题描述 springmvc+hbrat整合出现这个错误,求大神帮帮忙 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoBase' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'hibernateTemplate' while s

Mybatis3+Spring4+SpringMVC4 整合

   首先在整合这个框架的时候,想想其一般的步骤是怎样的,先有个步骤之后,不至于在后面的搞混了,这样在整合的时候也比较清晰些. 然后我们就细细的一步一步来整合. 1  创建一个Web项目.      2  导入Mybatis3.Spring4.SpringMVC4.连接数据库(我使用的数据库是mysql)的jar包.  我所用的包:     spring-websocket-4.2.0.RELEASE.jar   3  创建Mybatis3.Spring4.SpringMVC4.连接数据库的配置

springmvc+hibernate整合事务不回滚,求解

问题描述 最近心血来潮研究下了springmvc,发现比struts2好用多了,配置也方便,捣鼓了一阵,最后想把hibernate也整进去,结果悲剧就来了,事务就是不回滚,实在没招了,哪位大侠给看下,上代码 springmvc-servlet.xml <mvc:annotation-driven/><!-- 扫描注解时,将service,DAO层的注解排除,只扫描Controller注解 --><context:component-scan base-package=&quo