Spring AOP error - spring

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.

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.

Old versions of spring-integration-sftp in the spring-config file give the XML error but version 3.0.2 gives the error for outbound-channel-adapter

Please see the beginning of the spring-integration-config file below. If I have the reference to spring-integration-sftp (not version 3.02.) in the schema location I am receiving the following error:
Referenced file contains errors (http://www.springframework.org/schema/integration/spring-integration-2.0.xsd).
However, if I switch to the 3.0.2 version of spring-integration-sftp I am getting the following error:
The matching wildcard is strict, but no declaration can be found for element 'int-sftp:outbound-channel-adapter'.
The spring-integration-config.xml code related to spring-integration-sftp is as follows:
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="${seaWorldOrlando.sftp.host}" />
<property name="port" value="${seaWorldOrlando.sftp.port}" />
<property name="user" value="${seaWorldOrlando.sftp.user}" />
<property name="password" value="${seaWorldOrlando.sftp.password}" />
</bean>
<int-sftp:outbound-channel-adapter
id="sftpOutboundAdapter" channel="toFtp" charset="UTF-8"
remote-directory="/home/request" session-factory="sftpSessionFactory" />
The beginning of the spring-integration-config file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-3.0.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd">
Our recommendation do not use versions for XSD at all. The framework read the latest one from classpath. it allow you to avoid changes after upgrade.
From other side, if you mention 3.0.2 be sure you use correct jars of Spring Integration.
And all of them should be the same version.
If you have some doubts with allowed attributes, take a look into correct XSD, if they are present. You can find them in the appropriate jar, e.g. org/springframework/integration/sftp/config/spring-integration-sftp-3.0.xsd.

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>

mvc:annotation-driven does not work in 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

Can't load property file for property-placeholder

my property file is under the following path:
src\main\resources\META-INF\app-config.properties
and my spring configuration files are under the path:
WebContent\WEB-INF
and when trying to load the property file as follows:
<context:property-placeholder
location="classpath:META-INF/app-config.properties" />
i am getting the exception:
java.io.FileNotFoundException: class path resource [META-INF/app-config.properties] cannot be opened because it does not exist
applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<import resource="application-Security-Context.xml" />
<import resource="application-DataAccess-Context.xml" />
<import resource="application-Service-Context.xml" />
<context:component-scan base-package="com.myapp" />
<!-- PERSISTENCE -->
<context:property-placeholder
location="classpath:META-INF/app-config.properties" />
<jee:jndi-lookup id="appDS" jndi-name="MyApp" expected-type="javax.sql.DataSource"/>
<bean id="persistenceUnitManager"
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="appDS" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
<property name="persistenceUnitName" value="MyApp" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
applicationContext is loaded in web.xml as follows:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
i am using ant to build my project, am i missing ant configuration or eclipse configuration for this issue ?
ant config:
<zipfileset dir="${basedir}/src/main/resources/META-INF" includes="app-config.properties" fullpath="WEB-INF/classes/META-INF/app-config.properties"/>
also i added the META-INF folder to the deployment assembly in eclipse.
please advise how to load this property file correctly.
Can u try <context:property-placeholder
location="classpath*:META-INF/app-config.properties" />
If this also fails then may be your src\main\resources is not under the classpath.
I think the problem is in your path defined for properties file.
Can you try the following one.
<context:property-placeholder location="classpath:/META-INF/app-config.properties" />
Hope this helps you.
Taking a bit of a guess here, as you say you are using eclipse, but not exactly when the exception occurs - from eclipse or the command line. If from within Eclipse, then you will need to align the Eclipse project settings with those Ant is using. Go under Project-Properties, but rather than the deployment assembly, go to the Java Build path and verify that all of your source inputs (both code and resources) are there. More importantly, verify that the output directories are set to the same ones Ant is using. Long shot, but worth a try!
Is the properties file actually in your compiled artifact? Can you show us a directory listing of your unzipped artifact so we can see if the file is present? Or are you running it right from Eclipse and the error comes there? If so, you need to adjust your Project Properties to include the directory and/or file.

Resources