mvc:annotation-driven does not work in Spring - spring

I have the <mvc:annotation-driven/> annotation which errors out. The error I get is :
The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
When I used the beans
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
it works fine. How is that possible
My complete Spring context XML file is :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/
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-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-2.5.xsd">
<mvc:annotation-driven/>
</beans>

I believe that there is no mvc:annotation-driven annotation in Spring 2.5, I think it was introduced in Spring 3.0. Consider using the current version of Spring.
I could not find the actual http://www.springframework.org/schema/mvc/spring-mvc-2.5.xsd I'm not sure that it even existed.

Missign dependcy spring-webmvc, show your pom

Related

spring data - jpa application-context schema error

I am having an issue with the xml schema for spring jpa repository.
I have tried all the suggestions available online but do not seem to resolve it.
please help.
getting this error in the application-context.xml for the repository.
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 'repository:repositories'.
- cvc-complex-type.2.4.a: Invalid content was found starting with element 'repositories'. One of '{"http://www.springframework.org/schema/
beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean, WC[##other:"http://
www.springframework.org/schema/beans"]}' is expected.
my application context 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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<jdbc:embedded-database id="dataSource" type="H2" />
<tx:annotation-driven transaction-manager="transactionManager" />
<repositories base-package="com.company.repositories" />
<context:component-scan base-package="com.company.*" />
</beans>
We generally recommend to refer to the schema files that don't have version numbers in them as this will make sure you pick up the version form the dependency in your classpath.
The reason for this is that XSD doesn't know any kind of version concept. This means that spring-beans.xsd and spring-beans-3.0.xsd are completely unrelated to XSD which in turn means that if you happen to import both of them (I'll get to that in a second), this will create errors as XSD considers the types declared in them to be declared twice.
The reason you might accidentally import a non-versioned XSD is that the Spring Data XSDs actually refer to them to make sure we pick up the latest version (to be forward compatible).
Long story short: remove the explicit versions from the names and you should be good.
after a lot of trial and error the following application context doesn't seem to have any errors.
<?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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<jdbc:embedded-database id="dataSource" type="H2" />
<tx:annotation-driven transaction-manager="transactionManager" />
<jpa:repositories base-package="com.company.repositories" />
<context:component-scan base-package="com.company.*" />
</beans>
It beyond me why it didn't resolve the errors when I tried it earlier.
I was getting the following error.
Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-3.0.xsd).
I did the following, preferences > general > network connection > cache --> deleted the caches xsd.
Then I clicked on the problems view and deleted the problem and cleaned the project. Don't have the error now. Anybody who understands this better is welcome to answer.

spring context error with processing xml

I have problem with processing root-context with really simple content. I just want to configure camel-client and camel proxy beans but I get:
Error occured processing XML 'Provider
com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1
counts of IllegalAnnotationExceptions Class has two properties of
the same name "outputs" this problem is related to the following
location: at public java.util.List
org.apache.camel.model.ResequenceDefinition.getOutputs() at
org.apache.camel.model.ResequenceDefinition this problem is related to
the following location: at private java.util.List
org.apache.camel.model.ResequenceDefinition.outputs at
org.apache.camel.model.ResequenceDefinition '. See Error Log for more
details
This is my root-context.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:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<camel:camelContext id="camel-client">
</camel:camelContext>
<!-- Camel proxy for a given service, in this case the JMS queue -->
<camel:proxy
id="serviceProxy"
camelContextId="camel-client"
serviceInterface="pl.test.Service"
serviceUrl="jms:queue:test?transferException=true"/>
<bean id="jboss" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<jee:jndi-lookup id="connectionFactory" jndi-name="QueueConnectionFactory">
</jee:jndi-lookup>
</beans>
I have camel dependancies in my pom.xml. Anyone could give me a hint where I am doing the mistake?
According to the Camel proxy documentation <camel:proxy> must be within <camel:camelContext>:
<camel:camelContext id="camel-client">
<camel:proxy
id="serviceProxy"
camelContextId="camel-client"
serviceInterface="pl.test.Service"
serviceUrl="jms:queue:test?transferException=true"/>
</camel:camelContext>

Spring systemProperties not appending value properly

I am using Spring 3.1 to create a bean in an web application like below wherein the server contains -DCONFIG_MODE=dev. However, it seems spring is only resolving the filename to configuration.dev without appending the remaining .xml. Could you please point what could be wrong in 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:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd">
<bean id="xmlConfig" class="org.quwic.itms.mq.XmlConfiguration" init-method="init">
<constructor-arg type="java.net.URL" value="classpath:configuration.#{systemProperties.CONFIG_MODE}.xml"/>
<constructor-arg type="org.apache.commons.configuration.reloading.ReloadingStrategy" ref="reloadingStrategy"/>
</bean>
<!-- The managed reloading strategy for the configuration bean -->
<bean id="reloadingStrategy" class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy">
<property name="refreshDelay" value="300000"/>
</bean>
</beans>
Thanks,
Fixed it. I wrongly specified the system property as "-DCONFIG_MODE=local -Dprogram.name=JBossTools: JBoss 5.0 Runtime" rather than -DCONFIG_MODE=local "-Dprogram.name=JBossTools: JBoss 5.0 Runtime"

spring social xml config

i have already read the spring social document but the part of configuration is Java based, but my project's configuration is xml based. so please tell me how config spring social in spring xml config file. thank you and sorry for my poor english
Posting your code and issues will help us to provide you the best solution. Refer to the link below may be that is what you are looking for
http://harmonicdevelopment.tumblr.com/post/13613051804/adding-spring-social-to-a-spring-mvc-and-spring
Take a look at the example xml config
https://github.com/SpringSource/spring-social-samples/tree/master/spring-social-showcase-xml/src/main/webapp/WEB-INF/spring
You have to create a social config xml file and you have to import to your root-context.xml file. Also, you may think about configure your app with spring security. It's depends of your project architecture.
Sample spring social xml config 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:context="http://www.springframework.org/schema/context"
xmlns:social="http://www.springframework.org/schema/social"
xmlns:facebook="http://www.springframework.org/schema/social/facebook" xmlns:bean="http://java.sun.com/jsf/core"
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-3.2.xsd
http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd
http://www.springframework.org/schema/social/facebook http://www.springframework.org/schema/social/spring-social-facebook.xsd">
<!-- Ensures that configuration properties are read from a property file -->
<context:property-placeholder location="file:${sampleapp.appdir}/conf/appparam.txt"/>
<!--
Configures FB and Twitter support.
-->
<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}" />
<!--
Configures the connection repository. This application uses JDBC
connection repository which saves connection details to database.
This repository uses the data source bean for obtaining database
connection.
-->
<social:jdbc-connection-repository data-source-ref="sampleappDS" connection-signup-ref="accountConnectionSignup"/>
<!--
This bean is custom account connection signup bean for your registeration logic.
-->
<bean id="accountConnectionSignup" class="com.sampleapp.social.AccountConnectionSignup"></bean>
<!--
This bean manages the connection flow between the account provider and
the example application.
-->
<bean id="connectController" class="org.springframework.social.connect.web.ConnectController" autowire="constructor">
<constructor-arg index="0" ref="connectionFactoryLocator"/>
<constructor-arg index="1" ref="connectionRepository"/>
</bean>
Sample root-context.xml :
<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:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- Scan for Spring beans declared via annotations. -->
<context:component-scan base-package="com.sampleapp"/>
<context:annotation-config/>
<context:property-placeholder location="file:${sampleapp.appdir}/conf/appparam.txt"/>
<cache:annotation-driven/>
<!-- Root Context: defines shared resources visible to all other web components -->
<import resource="security-config.xml"/>
<import resource="classpath*:spring/bean-context.xml"/>
<import resource="classpath*:spring/persistence-config.xml"/>
<import resource="social-config.xml"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>

Spring AOP error

What would cause this problem at run-time?:
The matching wildcard is strict, but
no declaration can be found for
element 'aop:config'
Here is the relevant Spring XML:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
.
.
.
<aop:config>
<aop:advisor pointcut="execution(* acme.exam.driver.ui.components..*(..))"
advice-ref="loggingInterceptor" />
</aop:config>
<bean id="loggingInterceptor"
class="org.springframework.aop.interceptor.CustomizableTraceInterceptor">
<property name="enterMessage"
value="ENTER: $[targetClassShortName].$[methodName]($[arguments])" />
<property name="exitMessage"
value="EXIT: $[targetClassShortName].$[methodName]($[arguments]) = $[returnValue])" />
</bean>
</beans>
Note that I’ve already put aspectjweaver.jar and aspectjrt.jar on the class path.
Did you doublecheck the spring aop artifact on classpath ?
And according to my maven dependencies, aspectjweaver is not enough, i needed also aspectjrt.
Make sure that <spring-framework-directory>/dist/modules/spring-aop.jar is in your class path.
For anyone else, I resolved this error in my configuration, where the namespace included the item
xmlns:aop="http://www.springframework.org/schema/aop
though had not included the xsi:schemaLocation elements
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
This configuration error caused the message above.
Adding in the schemaLocation elements resolved it.

Resources