I am trying to add CSS
and JS
to JSP
page in a spring MVC
project so that I have included the reference of js/css
folder in dispatcher-servlet.xml
as below:
<?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>
But it is showing "The prefix "beans" for element "beans:beans" is not bound" in spring configuration file itself so can anyone help me out on this?
Look at your root element declaration - you've specified namespaces for the prefixes mvc
, xsi
, context
, p
, and tx
, but nothing for beans
. You've made "http://www.springframework.org/schema/beans"
the default namespace, but you haven't given it an alias of beans
.
The simplest fix here is probably just to do a search and replace to remove beans:
from the whole file - just let the default to its job.
Alternatively, change this:
xmlns="http://www.springframework.org/schema/beans"
to
xmlns:beans="http://www.springframework.org/schema/beans"
... and then check every element which doesn't have an explicit namespace prefix to see whether you actually mean it to be beans
. For example, consider:
<resources mapping="/js/**" location="/js/" />
If you're using explicit namespacing, that probably should be
<beans:resources mapping="/js/**" location="/js/" />
Although it sounds like it should actually be
<mvc:resources mapping="/js/**" location="/js/" />
It's in the beans namespace by default at the moment, but the mixture of defaulting and using a beans:
prefix is very confusing...
See more on this question at Stackoverflow