I'm placed statics folder css, js, images, wanted add sources on web-app
the xml seem can't be resolved.
report error is:
Cant resolve location statics, Spring Xml mode validaton
after open browser checked Sources, can't load js, images
<?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" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="com.f.dao, com.f.controller, com.f.service, com.f.advice"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/statics/" location="statics"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/users/"/>
<property name="suffix" value=".jsp"/>
</bean>
<aop:aspectj-autoproxy/>
</beans>
Related
I defined the beans definition in country-sg.xml file which I placed in the src/main/resources
Created the root-context.xml and imported above file as , I added root-context file web.xml file.
country-sg.xml file is not loading into context.
Can anyone help how to load this configuration file.
Thanks in advance.
root-context.xml file :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.kachakayala" />
<mvc:annotation-driven />
<import resource="classpath*: /country-sg.xml"/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
country-sg.xml file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean id="sg" class="com.kachakayala.services.CountrySg"></bean>
</beans>
In order to add the Bean sg in the application context, you have to scan the the configuration class country-sg.xml first. You can achieve this by adding the annotation #ComponentScan("package-of-your-config.xml") at your main class definition header.
I was getting the following error message while i was working with Spring with IntelliJ:
Failed to read schema document
'http://www.springframework.org/schema/beans/spring-context.xsd',
because 1) could not find the document; 2) the document could not be
read; 3) the root element of the document is not .
Help on this.
I was using wrong url in xsi:schemaLocation
Instead if using:
http://www.springframework.org/schema/beans/spring-context.xsd
I should have to used:
http://www.springframework.org/schema/context/spring-context.xsd
That solved my problem.
I crossed checked this with firing url into browser where within beans no spring-context.xsd was available.
Hope some of you can help with this.
#Indrajeet : The proper spring.xml or application-context.xml format :
<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.demo" />
<mvc:annotation-driven/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
I am currently working on spring and I am very much new to this framework. I have added all the required jars of spring and written the following spring-dispatcher-servlet.xml file.
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.quiz_mcq.controller, com.quiz_mcq.service, com.quiz_mcq.dao"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
My code works fine when there is internet connection but breaks down when I am not connected to the internet. And gives the following error.
Line 12 in XML document from ServletContext resource [/WEB-INF/spring->dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 109; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.
What am I doing wrong here?
Can any tell me the solution what needs to be done to work the project even offline?
for xsi schema Location put
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
classpath:org/springframework/beans/factory/xml/spring-context-3.0.xsd"
in your case code need to check on springframework.com every time
the schema location i provided should work because the xsd is packaged inside the spring jar here
I imported the cineast maven project to eclipse, but I face a configuration problem...
cvc-complex-type.4: Attribute 'base-package' must appear on element 'neo4j:config'
Below are the configuration files which have this error.
ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
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/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config/>
<context:component-scan base-package="org.neo4j.cineasts">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<context:spring-configured/>
<neo4j:config storeDirectory="target/data/graph.db"/>
<neo4j:repositories base-package="org.neo4j.cineasts.repository"/>
<!--neo4j:config graphDatabaseService="graphDatabaseService"/>
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474"/>
</bean-->
<bean class="org.neo4j.cineasts.movieimport.MovieDbApiClient">
<constructor-arg value="926d2a79e82920b62f03b1cb57e532e6"/>
</bean>
<bean class="org.neo4j.cineasts.movieimport.MovieDbLocalStorage">
<constructor-arg value="data/json"/>
</bean>
<tx:annotation-driven mode="proxy"/>
</beans>
movie-test-context.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
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/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="org.neo4j.cineasts"/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:repositories base-package="org.neo4j.cineasts.repository"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<bean class="org.neo4j.cineasts.movieimport.MovieDbApiClient">
<constructor-arg value="926d2a79e82920b62f03b1cb57e532e6"/>
</bean>
<bean class="org.neo4j.cineasts.movieimport.MovieDbLocalStorage">
<constructor-arg value="data/json"/>
</bean>
<tx:annotation-driven mode="proxy"/>
</beans>
Have a look at http://blog.neo4j.org/2014/03/spring-data-neo4j-progress-update-sdn-3.html
This is actually a duplicate question from earlier on Stack, but, long and short is that if you're using the latest SDN (and I'm pretty sure you are), then you need to include the "base-package" attribute in both the neo4j:config and neo4j:repositories elements.
In the link above, Michael Hunger explains this and you can clearly see what the values for those attributes should be.
HTH
I've created Spring 3 MVC project via Spring Tool Suite template and I have integrated Spring security there.. Everything works except accessing the static content.
When I create only MVC app and have my static content in /src/webapp/WEB-INF/resources/and put <resources mapping="/resources/**" location="src/main/webapp/WEB-INF/resources" /> to my applicationContext.xml, it works well...But I can't add this code to my applicationContext.xml with security...the code doesn't even compile..Any idea what to write to my web.xml to make this work?
My applicationContext.xml file looks like this:
<?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:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="cz.cvut.fit.genepi.controllers" />
<import resource="classpath:applicationContext-security.xml" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
It's weird that when using code above, mapping view-controller works allrigh, but when I'm using this, I get this error The prefix mvc:resources is not bound
<?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:security="http://www.springframework.org/schema/security"
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.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="cz.cvut.fit.genepi.controllers" />
<import resource="classpath:applicationContext-security.xml" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>
structure of the solution:
The code should be in your app context definition(applicationContext.xml), and the location is relative to deployment root :
<mvc:resources location="/resources/" mapping="/resources/**"/>
you'll need this at top of config file
xmlns:mvc="http://www.springframework.org/schema/mvc"
and then
xsi:schemaLocation = http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
I think there may be someo confusion, the normal wdirectory structure is something like this:
src/main/java
src/main/resources
src/main/webapp
src/main/webapp/WEB-INF
src/main/webapp/WEB-INF/jsps
src/main/webapp/css
The css directory is just an example, I acually have javascipt, and image directries as well, some people prefer just one called for example "static-assets". But calling it resources is rather confusing. The src/main/resource/ directory actually contains config files for the whole project (I put my appContext.xml's in there and log.properties files), it gets copied to WEB-INF on deployment and should not be used for mapping an static resources.
Eg, in my example woul dactualyl be mapped like this :
<mvc:resources location="/css/" mapping="/css/**"/>