I am trying to upgrade my spring 3.4 application to spring 4.0.2
I imported all the spring-4.0.2 jar files but am getting errors in the dispatcher-servlet.xml
if I use this code, I get Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-4.0.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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">
<!-- automatic scan base folder to detect controllers -->
<context:component-scan base-package="com.shaw.csdss"/>
<mvc:annotation-driven />
<!-- This file will contain the view name mappings to the jsp -->
<bean id = "jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix"><value>/</value></property>
<property name="suffix"><value>.jsp</value></property>
<property name="order" value="1" />
</bean>
</beans>
I tried to remove the -4.0 from the xsd references but I get same error on spring-mvc-xsd now.
I even tried to discard everything and just copy the xml from the spring reference documentation as follow
<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"
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">
<mvc:annotation-driven />
<bean id = "jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix"><value>/</value></property>
<property name="suffix"><value>.jsp</value></property>
<property name="order" value="1" />
</bean>
</beans>
but with this simple file I get error on
cvc-complex-type.2.4.c: the matching wildcard is strict, but no declaration can be found of element 'mvcannotation-driven
Any example I take from spring4.0 reference document, gives me same error.
is this a problem with spring4.0.2 or am I missing something?
Thank you for your help
Related
I have an old codebase that uses camel 2.something. We have to upgrade to camel 3.14 for Nexus-flagged security issues. I'm going through the Upgrade Camel 2 to 3 docs. I see that Main moved packages, which I did, but now I'm getting an error that Main.setApplicationContextUri("camel-context.xml") is no longer a method on Main. I can't find it, nor a replacement in the upgrade docs.
What am I missing?
Also, if there's a way to do a simple camel config via beans and annotations instead of xml, I'd love a pointer to that. I'm also running into an issue parsing the camel-context.xml, so if I can get rid of that whole mess, I'd love to.
We are using Java 8 so I think the latest that works with that is Camel 3.14.6 so that's what I'm trying.
Here's our camel-context.xml:
<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:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:camel="http://camel.apache.org/schema/spring"
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://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<!-- ================================== -->
<!-- Define camel context -->
<!-- ================================== -->
<camel:camelContext id="camel" trace="false">
<camel:propertyPlaceholder id="queriesConfig" location="lib/queries.properties" />
<!-- Location for route scan -->
<camel:package>com.blah.listener</camel:package>
</camel:camelContext>
<!-- configure the Camel SQL component to use the JDBC data source -->
<bean id="sqlComponent" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="bean1" class="com.foo.OurThing" />
<bean id="bean2" class="com.bar.OtherThing" />
Edit: Just found this. Are we supposed to convert camel-context.xml to application.properties? We also have an app-context.xml for basic Spring configuration, and there's a reference to the camel-context.xml there. I wonder if we replace camel-context.xml with application.properties, what to do with this reference? Just remove it, or change it?
I have tried to set the default validation message file to messages.properties file. It worked. However, for some reason the primary attribute inside validator bean is marked red in the applicationContext.xml file.
The error message, "Attribute primary is not allowed here".
I have tried to find the reason of this in many resources and cross-checked many possibilities, but everything seems fine with my configuration.
I use Intellij Idea, Spring version - 3.2.17 RELEASE, Hibernate version - 3.6.10.Final.
Can anyone explain the reason ?
applicationContext.xml -
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd"
default-autowire="byName">
<context:component-scan base-package="com.test.leavemanagement"/>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
</bean>
<mvc:annotation-driven validator="validator"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" primary="true">
<property name="validationMessageSource" ref="messageSource"/>
</bean>
</beans>
Update :Now Working properly. Kindly follow the comments.
This is my Spring configuration file:
<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: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="report.frontcontroller"/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"> <value>/WEB-INF/</value></property>
<property name="suffix"> <value>.jsp</value></property>
</bean>
</beans>
All jars are included in this project, and the configuration file is shown above. I get errors for this part:
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
Errors: * Matching wildcard is strict but no declaration is found for mvc:resource and mvc:annotation
* Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources'.
- schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/mvc/spring-
mvc-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document
is not .
Multiple annotations found at this line:*
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources'.
- schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/mvc/spring-
mvc.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document
is not .
can you try below configuration that is copied from GIT - spring-mvc-showcase
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<task:annotation-driven />
</beans:beans>
change to spring-mvc.xsd to spring-mvc-3.0.xsd .Similarly change at all the remaining places too.
Refer here
Edit
<?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:aop="http://www.springframework.org/schema/aop" 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.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="report.frontcontroller" />
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
I need to set Spring MVC interseptors to catch url parameter language and accordingly get data from .properties file. Getting error Cannot resolve propertyparamName when configuring context in servlet-config.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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
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-3.2.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/pdfs" location="pdfs"/>
<context:component-scan base-package="com.ttu.cs.controller"/>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean id="LocaleResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en"/>
<!-- Declare the Interceptor -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="paramName" value="language"/>
</bean>
</mvc:interceptors>
</beans>
I think you meant to use org.springframework.web.servlet.i18n.LocaleChangeInterceptor rather than SessionLocaleResolver.
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language"/>
</bean>
This class is a HandlerInterceptor and does have a paramName property.
SessionLocaleResolver, on the other hand, is not.
Not sure what you expect but SessionLocaleResolver doesn't have such a param. Maybe you meant locale?
I have the requirement of returning JSON/XML data from my controller.From what i found,I needed #ResponseBody in my method and for that I need <mvc:annotation-driven> enabled. I have tried all sorts of RnD but am still stuck! :(
Apparently my problem lies in my servlet.xml file (the schema isnt getting validated!)
I am using Spring 3.1.1 & have explicitly put in spring-mvc-3.1.1.jar in my classpath.
Here's my servlet-context file sample-servlet.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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc-3.1 http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
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">
<context:component-scan base-package="com.sample.controller"/>
<mvc:annotation-driven/>
<!--Use JAXB OXM marshaller to marshall/unmarshall following class-->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="xmlViewer"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.sample.model.SampleClass</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>
My controller class looks like this :
#Controller
public class XmlController {
#RequestMapping(value="/getXml",method = RequestMethod.POST)
public #ResponseBody AssociateDetail getXml(){
System.out.println("inside xml controller.....");
AssociateDetail assoBean=null;
try{
AssociateService add=new AssociateService();
assoBean=add.selectAssociateBean();
}catch(Exception e){
e.printStackTrace();
}
return assoBean;
}
}
Now the problem is <mvc:annotation-driven /> gives error:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
And I have tried all the workarounds suggested on this site and beyond. Have updated my schema namespaces, using Spring 3.1.1 and #ResponseBody.
As the error suggests there's something wrong with the schema declaration. You do not have the xsd s declared.
Use this instead.
<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.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
Add the following schemas to your schemaLocation declaration at the top:
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd