I'm testing the Spring cache and, this is my context file
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven cache-manager="simpleCacheManager"/>
<bean id="simpleCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
<property name="name" value="alfresco"/>
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
<property name="name" value="alfresco_article"/>
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
<property name="name" value="alfresco_action"/>
</bean>
</set>
</property>
</bean>
I added all required library but, I cannot validate the library because Eclipse still tells me that AOPAlliance.jar and org.springframework.context-3.1.1.RELEASE.jar are missing.
The error is:
Multiple annotations founds at this line: class org.springframework.cache.concurrent.ConcurrentCacheFactoryBean not found.
SOLVED changing to org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean
but, calling the url this happens:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [configuration-context.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [configuration-context.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
aop-alliance.jar and org.springframework.aop-3.1.1.RELEASE.jar are both in classpath.
Any clue?
Thanks,
Andrea
Double-check that org.springframework.context-3.1.1.RELEASE.jar is indeed on the classpath. Both Eclipse validation and the error point at this issue.
UPDATE: I've checked, and you are right. ConcurrentCacheFactoryBean seems to be removed since 3.1.0.M1 and is possibly replaced by ConcurrentMapCacheFactoryBean in the same package. I wasn't able to find any proof in the release notes yet. However, if you change the bean class name for your caches to ConcurrentMapCacheFactoryBean, it does seem to work fine.
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean">
<property name="name" value="alfresco"/>
</bean>
UPDATE2: Yes, indeed ConcurrentCacheFactoryBean has been renamed to ConcurrentMapCacheFactoryBean. They just didn't get around to update the tutorial.
Related
I got the following error :
Error creating bean with name
'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'
defined in class path resource [jpaDaoContext.xml]: Initialization of
bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'vodEntityManagerFactory' defined in class
path resource [jpaDaoContext.xml]: Invocation of init method failed;
nested exception is javax.persistence.PersistenceException:
[PersistenceUnit: vodPersistenceUnit] class or package not found
I had a look on Google and I was told to choose transaction-type=RESOURCE_LOCAL but the settings were already that way. What is wrong with these settings :
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<!-- transaction-type is RESOURCE_LOCAL or JTA -->
<persistence-unit name="vodPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<class>mypackage.persistent.HistoriqueAction</class>
<class>mypackage.persistent.ParametresTechniques</class>
<class>mypackage.persistent.TicketType</class>
<class>mypackage.persistent.TransactionType</class>
<class>mypackage.persistent.StatutSession</class>
<class>mypackage.persistent.Statistique</class>
<class>mypackage.persistent.StatUser</class>
<!-- Avoid to scan *.class and *.hbm.xml -->
<exclude-unlisted-classes />
</persistence-unit>
</persistence>
Regards
I fixed the issue. I had to comment these three lines in the file "persistence.xml" :
<!--class>mypackage.persistent.TicketType</class>
<class>mypackage.persistent.TransactionType</class>
<class>mypackage.persistent.StatutSession</class-->
For the moment i have no idea why it fixes the issue. It is really hard to debug this spring file.
If you had to comment out the "class" elements, it is likely that one of those classes is either not defined, or is not available in the classpath.
I faced the same exact error, and it was resolved once the fully qualified names were all correct. Ideally, Hibernate should tell you what class is not found, but sadly it does not do it in this case.
You you haven't done that, put <property name="persistenceUnitName" value="vodPersistenceUnit" /> in your jpaDaoContext.xml as property of your entityManagerFactory bean definition like:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="vodPersistenceUnit" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">...</property>
</bean>
I was running into this exception when trying to run a Spring Boot application in WebLogic 12.1.3 In the dependency tree I found out spring-tx was being included from one of the common project libraries. Our particular app only calls web service so there is no need for database access. So in the library dependency I added:
<exclusions><exclusion> <groupId>org.springframework</groupId><artifactId>spring-tx</artifactId></exclusion></exclusions>
I got this error when i restart the tomcat "Context initialization failed"
[ERROR][2013-02-26 15:48:49,432][ContextLoader] - [Context initialization failed]
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [applications\applications.xml]
Offending resource: ServletContext resource [/WEB-INF/config/context/appContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [..\..\..\..\schema\ab- products\common\resources\appContext-services.xml]
Offending resource: ServletContext resource [/WEB-INF/config/context/applications/applications.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/schema/ab-products/common/resources/appContext-services.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/schema/ab-products/common/resources/appContext-services.xml]
Here is appContext-services.xml,it exists in /schema/ab-products/common/resources/appContext-services.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:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<!-- ========================= Start of SERVICE DEFINITIONS ========================= -->
<!--
Per-activity configuration bean.
-->
<bean id="AbCommonResources-configuration"
class="com.archibus.service.cost.Configuration">
<property name="defaultDateStart" value="1980-01-01" />
<property name="defaultDateEnd" value="2099-12-31" />
</bean>
<!--
Remote version of CostService. This service is not used when the client calls WFRs.
TODO: fix proxyInterfaces="com.archibus.utility.Immutable": define and use ICostService interface.
-->
<bean id="CostService-remote"
class="org.springframework.aop.framework.ProxyFactoryBean"
p:proxyInterfaces="com.archibus.utility.Immutable"
p:target-ref="CostService">
<property name="interceptorNames">
<list>
<value>securityInterceptor</value>
<value>exceptionHandlingInterceptor</value>
</list>
</property>
</bean>
<!--
Local version of CostService, used by WFRs.
-->
<bean id="CostService"
class="com.archibus.service.cost.CostService"
scope="prototype"
p:configuration-ref="AbCommonResources-configuration">
</bean>
<!--
Cost beans.
-->
<bean id="actualCost"
class="com.archibus.app.common.finance.domain.ActualCost"
scope="prototype">
</bean>
<bean id="scheduledCost"
class="com.archibus.app.common.finance.domain.ScheduledCost"
scope="prototype">
</bean>
<bean id="recurringCost"
class="com.archibus.app.common.finance.domain.RecurringCost"
p:configuration-ref="AbCommonResources-configuration"
scope="prototype">
</bean>
here is applications.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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<import resource="..\..\..\..\schema\ab-products\common\resources\appContext-services.xml" />
thank you for your response, i solve this issue. It s about to java version. I changed my java version 1.4 to 1.6 so now there is no problem.
Goodness - here's your problem:
java.io.FileNotFoundException: Could not open ServletContext resource [/schema/ab-products/common/resources/appContext-services.xml]
Spring couldn't find that app context XML in the CLASSPATH.
Check the location and the way you've declared it in the web.xml. One or both are wrong.
the problem might be the your xml file location
FileNotFoundException means it is unable to find the file in that path.
The stack error is pretty clear .
Context initialization fails when it loads the
/WEB-INF/config/context/applications/applications.xml
I gues you import following file ,
/schema/ab-products/common/resources/appContext-services.xml
move the file to
/WEB-INF/config/context/applications/ and update you import statement in applications.xml
The problem appears to be:
nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/schema/ab-products/common/resources/appContext-services.xml] at
Is appContext-services.xml present in the specified location, and readable (ie has the right permissions)?
I'm trying to use Spring's JdbcTemplate to simplify my DAOs in a Java web service that is deployed in Tomcat and connects to Postgres.
I'm following Spring's documention, and I'm trying configure a DataSource in the application context file, as follows:
<?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"
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">
<context:component-scan base-package="com.manta" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<context:property-placeholder location="/WEB-INF/db.properties"/>
</beans>
I have the following db.properties file in the appropriate place:
driverClassName=org.postgresql.Driver
url=jdbc:postgresql://pgprod.ecnext.com:5432/manta
username=my_user_name
password=my_password
When I try to deploy, I find the following stack trace in catalina.out:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException:
Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/context.xml]:
Could not resolve placeholder 'driverClassName'
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:656)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:842)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Things that are NOT the problem:
The db.properties file is in the correct location.
The credentials in the db.properties are correct, and can be read in manually to connect to the database.
The context.xml file is being found by the ContextLoaderListener, and I am able to inject other dependencies.
I would very much appreciate any suggestions as to what could cause this. I'm using Spring 3.1.1, and Tomcat 7.0.26.
You probably have multiple <context:property-placeholder ... > in your project which each create a new instance of the underlying object, and is a doorway to pains...
I prefer using the following declaration for loading property files:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db-config.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
Drop the leading slash from your location (i.e. location="WEB-INF/db.properties" ) or better yet change it to classpath:
location="classpath:db.properties"
use org.springframework.jdbc.datasource.DriverManagerDataSource
instead of org.apache.commons.dbcp.BasicDataSource
Use ignore-unresolvable="true" in you application context. Default value is 'fales' you need to set it 'true' so pass on the key to any others in the context that have not yet visited.
<context:property-placeholder ignore-unresolvable="true" location="/WEB-INF/application.properties" />
<context:property-placeholder ignore-unresolvable="true" location="/WEB-INF/dbcp.properties"/>
Make sure you have the maven dependency properly, Sping-core and Spring-context dependencies should be present in your project.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version></version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version></version>
</dependency>
On my web.xml I have a "springmvc" servlet declaration (which has a corresponding springmvc-servlet.xml)
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/myapp/*</url-pattern>
</servlet-mapping>
I also have my usual applicationContext.xml file.
Which one gets loaded first? The springmvc-servlet.xml or the applicationContext.xml?
The reason I'm asking this is whenever I place the <mvc:annotation-driven/> element in the applicationContext.xml, I get a Severe Context error. But when I put that element in the springmvc-servlet.xml, my web app runs fine.
Any ideas why?
On another web-app, I have the <mvc:annotation-driven/> inside the applicationContext.xml and it runs fine.
Addendum:
I do notice that the presence of aop:config poses conflict against mvc:annotation-driven
the applicationContext.xml context is parent to the dispatcher-servlet.xml context. I don't know whether this means it is loaded first, but it does not matter in your case:
<mvc:annotation-driven /> must be in the dispatcher-servlet.xml, because it belongs to the web-part of the application.
I solved my problem!
It turns out it has nothing to do with the load order or where the <mvc:annotation-driven/> is declared.
I tried deploying my web-app on another Tomcat and to my surprise there's a stack trace in the localhost log. I had a hint by trial and error that the conflict is with <aop:config/>. But what particular conflict?
Then I saw this error in the log file:
java.lang.ClassCastException: org.aspectj.weaver.ResolvedType$Array cannot be cast to org.aspectj.weaver.ReferenceType
So we have a cast exception. I googled that exact error above and found this: Spring 3: adding causes ClassCastException
It appears the thread starter and I have the same exact issue. So I downloaded the aspectj-1.6.10.jar but I was still missing a class. Then it turns out it should be the aspectjweaver-1.6.9
I was still using a very old aspectjweaver. It didn't have any version on its name. Problem solved. Case closed.
By the way as a bonus, I've manually unrolled the <mvc:annotation-driven/> element to its equivalent xml declaration:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" />
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="validator" ref="validator" />
</bean>
</property>
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
They're exactly the same when you declare the <mvc:annotation-driven/> based on what I've researched.
Thanks to everybody who helped me out.
Except for web.xml there is no predefined order.
This happens:
web.xml is loaded by the servlet engine, this triggers the load of all defined servlets, filters, listeners,
the ContextLoaderListener loads the
root application context XML, this
might include a bean definition for a
LocalSessionFactoryBean, triggering
the load of all Hibernate mapping XML
files
the DispatcherServlet loads the web
application context XML
Study the web.xml to determine the order in each case.
see also:
link
You probably have to add the mvc namespace to the application context:
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
>
(other namespaces stripped)
In dependency A I have the following:
<beans>
<bean
id="simplePersonBase"
class="com.paml.test.SimplePerson"
abstract="true">
<property
name="firstName"
value="Joe" />
<property
name="lastName"
value="Smith" />
</bean>
</beans>
And then in project B, I add A as a dependency and have the following config:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
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">
<bean
id="simplePersonAddress01"
parent="simplePersonBase">
<property
name="firstName"
value="BillyBob" />
<property
name="address"
value="1060 W. Addison St" />
<property
name="city"
value="Chicago" />
<property
name="state"
value="IL" />
<property
name="zip"
value="60613" />
</bean>
</beans>
When I use ClassPathXmlApplicationContext like so:
BeanFactory beanFactory = new ClassPathXmlApplicationContext( new String[] {
"./*.xml" } );
SimplePerson person = (SimplePerson)beanFactory.getBean( "simplePersonAddress01" );
System.out.println( person.getFirstName() );
Spring complains as it can not resolve the parent xml.
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'simplePersonBase' is defined
I am sure there is a way to do this, however, I have not found it. Does anyone know how?
Try with the classpath*: prefix.
Does A.jave have the corresponding xml file? In project A, did you the xml inside src/main/resources?
Not really an answer to the question - but beware of this approach.
It can be a nightmare resolve errors. Imagine getting an spring error on startup - the only way to resolve it is cracking open all the jars to find any application contexts held within.
At the very least put the application context files in a distinct package and specify any you wish to use by name.
A *.xml from the root of the classpath is a recipe for disaster.