2016-07-29 78 views
0

我想补充CSSJSJSP页面在spring MVC项目,以便我在dispatcher-servlet.xml如下列入js/css文件夹的参考:前缀“豆”的元素“豆:豆”未绑定

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


    <context:annotation-config /> 
    <context:component-scan base-package="com.asurion" /> 

    <resources mapping="/js/**" location="/js/" /> 
    <resources mapping="/css/**" location="/css/" /> 

    <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
      <value>/WEB-INF/jsp/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </beans:bean> 

    <beans:bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </beans:bean> 
    <beans:bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
     p:location="/WEB-INF/jdbc.properties" /> 

    <beans:bean id="dataSource" 
     class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" 
     p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
     p:url="jdbc:sqlserver://localhost:1433;DataBaseName=test" p:username="test" 
     p:password="test" /> 


    <beans:bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation"> 
      <value>classpath:hibernate.cfg.xml</value> 
     </property> 
     <property name="configurationClass"> 
      <value>org.hibernate.cfg.AnnotationConfiguration</value> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">com.asurion.dialect.SQlServerDBDialect</prop> 
       <prop key="hibernate.show_sql">true</prop> 
      </props> 
     </property> 
    </beans:bean> 

    <beans:bean id="reportDAO" class="com.asurion.dao.ReportDaoImpl"></beans:bean> 
    <beans:bean id="reportManager" class="com.asurion.service.ReportManagerImpl"></beans:bean> 

    <tx:annotation-driven /> 
    <beans:bean id="transactionManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </beans:bean> 

</beans:beans> 

但它显示“spring:配置文件本身没有绑定元素”beans:beans“的前缀”beans“,所以任何人都可以帮我解决这个问题吗?

+0

删除根元素的bean前缀 –

+0

将'beans:beans'替换为'beans'应该可以工作。 –

回答

6

看看你的根元素声明 - 您所指定的命名空间的前缀mvcxsicontextp,并且tx,但没有为beans。您已将"http://www.springframework.org/schema/beans"设为默认命名空间,但您没有给它一个别名beans

这里最简单的修复方法可能只是做一个搜索并替换从整个文件中删除beans: - 只是让默认的工作。

另外,更改此:

xmlns="http://www.springframework.org/schema/beans" 

xmlns:beans="http://www.springframework.org/schema/beans" 

...然后检查其没有明确的命名空间前缀的每一个元素,看看是否你实际上意味着它为beans。例如,考虑:

<resources mapping="/js/**" location="/js/" /> 

如果您使用明确的命名空间,这大概应该是

<beans:resources mapping="/js/**" location="/js/" /> 

虽然听起来像它应该实际上

<mvc:resources mapping="/js/**" location="/js/" /> 

它在bean名称空间此刻默认为默认值,但混合使用前缀beans:非常混淆......

+0

我从配置文件中删除了

+0

@tanajimane:那听起来像是一个不同的问题。你确定这不是'mvc'吗? –

+0

天啊!我错过了......这回答了我的问题。非常感谢 –