I'm with a JEE project, from Maven project to Dynamic Web.
The problem is that I haven't use xml configuration, but now, with the Dynamic web project, I must.
I can't figure out how write right the applicationContext.xml; I've read a lot of topic but no one help me.
Here the code and error:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
<!-- Abilita l'uso di tutte le annotazioni -->
<context:annotation-config/>
<import resource="security-config.xml"/>
<context:component-scan base-package="it.**"/>
<!-- Abilita il supporto AOP -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<util:properties id="settings" location="classpath:../../META-INF/MANIFEST.MF"/>
<!-- i valori delle properties vengono iniettati in AuthentificationFilter e il id=myProps serve per l'iniezione -->
<util:properties id="myProps" location="classpath:muru/application.properties"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:muru/*.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg>
<bean class="com.mongodb.MongoClient">
<constructor-arg value="localhost"/>
<constructor-arg value="27017"/>
</bean>
</constructor-arg>
<constructor-arg value="database"/>
</bean>
<mongo:repositories base-package="it.cap.domain" mongo-template-ref="mongoTemplate"></mongo:repositories>
<!-- Abilita la configurazione delle transazioni tramite annotazioni -->
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
</beans>
Stacktrace
11:12:26.108 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 68 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 68; columnNumber: 93; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mongo:repositories'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mongo:repositories'.
Can you help me to understand?
Thanks in advice :)
The issue seems to be from the order of the bean definition in your context file.
Just try changing the position of the below bean definition
<tx:annotation-driven transaction-manager="txManager"/>
from currrent position to just after the below bean.
<context:component-scan base-package="it.**"/>
Something like
<context:component-scan base-package="it.**"/>
<tx:annotation-driven transaction-manager="txManager"/>
See if this solves your issue.
For your reference..
http://forum.spring.io/forum/spring-projects/container/9895-order-of-bean-definitions-matters
If the above solution doesn't works ,last thing I guess would be to check if right jars holding the specified mongo related xsds under your application's lib folder
I found a solution, in applicationContext.xml I just put an import tag to resource "spring.xml":
<import resource="spring.xml" />
And inside spring.xml:
<!-- MongoDB host -->
<mongo:mongo host="localhost" port="27017" />
<!-- Template for performing MongoDB operations -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate" c:mongo-ref="mongo" c:databaseName="dbname" />
<!-- Activate Spring Data MongoDB repository support -->
<mongo:repositories base-package="it.domain" mongo-template-ref="mongoTemplate" />
<!-- Use this post processor to translate any MongoExceptions thrown in #Repository annotated classes -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
Now it starts without tomcat's crash; I wil let you know if it works fine with db's connections.
Related
I have created a JUnit test in spring with next code:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = {
"classpath:*/WEB-INF/demo-servlet.xml"})
public class CrudTestJUnit extends AbstractJUnit4SpringContextTests {
#Autowired
protected ShoppingCartDao shoppingCartDao;
#Autowired
private ApplicationContext context;
#Before
public void setUp(){
}
#Test
public void testSomething() {
System.out.println("Evo beanvoa:" + Arrays.toString(context.getBeanDefinitionNames()));
Assert.assertTrue(false);
}
}
In demo-servlet.xml i defined bean:
<bean id="shoppingCartDao" class="com.it355.hibernatecrud.dao.impl.ShoppingCartDaoImpl"></bean>
When i run JUnit test i get this error:
Error creating bean with name 'CrudTestJUnit': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.it355.hibernatecrud.dao.ShoppingCartDao CrudTestJUnit.shoppingCartDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.it355.hibernatecrud.dao.ShoppingCartDao] found for dependency:
When i delete shopping cart i get this from getBeanDefinitionNames():
Evo beanvoa:[org.springframework.context.annotation.internalConfigurationAnnotationProcessor,
org.springframework.context.annotation.internalAutowiredAnnotationProcessor,
org.springframework.context.annotation.internalRequiredAnnotationProcessor,
org.springframework.context.annotation.internalCommonAnnotationProcessor,
org.springframework.context.annotation.internalPersistenceAnnotationProcessor,
org.springframework.context.event.internalEventListenerProcessor,
org.springframework.context.event.internalEventListenerFactory,
org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor, org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]
Here is my full demo-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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--Kako bi Hibernate mogao da se poveže na bazu podataka potrebno je kreirati sesiju. To radimo u sledećem
zrnu-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" >
<!--Dodavanje path-a na kome se nalaze podešavanja za Hibernate -->
<value>classpath:hibernate.cfg.xml</value>
</property>
<!-- Dodavanje path-a paketa u kome se nalaze entity fajlovi na osnovu kojih
će Hibernate kreirati bazu i upisivati u nju-->
<property name="packagesToScan">
<list>
<value>com.it355.hibernatecrud.entity</value>
</list>
</property>
</bean>
<!--Transakcija se dešava između baze i programa korišćenjem Transaction Managera koji definišemo ovde
On koristi sesiju koju smo definisali iznad -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="shoppingCartDao" class="com.it355.hibernatecrud.dao.impl.ShoppingCartDaoImpl"></bean>
<bean id="persistenceExceptionTranslationPostProcessor"
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<context:component-scan base-package="com.it355.hibernatecrud" />
<mvc:annotation-driven conversion-service="conversionService" />
<tx:annotation-driven />
<mvc:default-servlet-handler />
<mvc:resources mapping="/css/**" location="/WEB-INF/css/"/>
<mvc:resources mapping="/resources/**" location="/WEB-INF/" />
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="com.it355.hibernatecrud.converter.IntegerToCategory" />
</set>
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
Am i wrong in calling configuration file or some other thing? Is there someone who had the same issue.
Also in my configuration file i have component scan configured and my application works and loads beans without any problem but JUnit is making a problem.
It seems that your XML configuration file can't be found or loaded properly, thus you aren't able to do the injections properly.
I suggest just use classpath, if your XML configuration file is within your CLASSPATH there's no need to mention WEB-INF etc'. Like this:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("classpath:demo-servlet.xml")
public class CrudTestJUnit extends AbstractJUnit4SpringContextTests {
}
In the end i found out that Configuration from WEB-INF must be loaded like this:
#ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/demo-servlet.xml"})
I am new to WebLogic and fairly new to Hibernate / Spring applications, as my primary language is C# and my primary servers have always been Windows Servers, so please forgive any simple errors I may have.
I am having trouble deploying to our WebLogic 10.3.4 server. It works locally on my WebLogic instance, but not on the remote server.
I am using Hibernate 4.2.8 for persistence and Spring MVC 4.0 for my web application framework. The error I am receiving is:
Failed to load webapp: 'ncms2_May20.war'
Message icon - Error Substituted for missing class Exception [EclipseLink-28010] (Eclipse Persistence Services - 2.1.2.v20101206-r8635) - org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: PersistenceUnitInfo ncms2 has transactionType JTA, but does not have a jtaDataSource defined.
I am using a Spring annotation based Hibernate configuration file.
package mil.navy.navsupbsc.utilities;
import java.util.Properties;
import javax.sql.DataSource;
import com.app.AuditInterceptor;
import org.hibernate.SessionFactory;
import org.hibernate.dialect.Oracle10gDialect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
#Configuration
public class HibernateConfiguration {
#Value("#{dataSource}")
private DataSource dataSource;
#Bean
public LocalSessionFactoryBean sessionFactoryBean() {
Properties props = new Properties();
props.put("hibernate.dialect", Oracle10gDialect.class.getName());
props.put("hibernate.format_sql", "true");
props.put("hibernate.hbm2ddl.auto", "update");
props.put("hibernate.show_sql", "true");
props.put("hibernate.format_sql", "true");
props.put("hibernate.use_sql_comments", "true");
LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
bean.setEntityInterceptor(new AuditInterceptor());
bean.setPackagesToScan(new String[] { "com.app.entity" });
bean.setHibernateProperties(props);
bean.setDataSource(this.dataSource);
return bean;
}
#Bean
public HibernateTransactionManager transactionManager() {
return new HibernateTransactionManager(sessionFactoryBean().getObject());
}
}
My Spring 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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="transactionManager" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="com.app" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
Could any of you assist me in getting this to work? I appreciate any and all help. Thank you!
Update
I did the following to switch it to JTA:
added a JtaTransactionManager in the Hibernate java configuration file rather than using the HibernateTransactionManager.
set the JtaTransactionManager property in the LocalSessionFactoryBean
added a jdni lookup in the spring-servlet file
added a resource reference in both the web.xml and weblogic.xml files
removed the data source in spring-servlet and removed the reference to it in the hibernate java configuration file
created a data source on the server
Still not working 100% though. Will keep this updated.
UPDATE: Here's a helpful resource that I've been using (http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/)
You haven't posted your persistence.xml JPA configuration file but it may contain something like:
<persistence-unit name="..." transaction-type="JTA">
<jta-data-source>java:/DefaultDS</jta-data-source>
When deploying on application servers you should benefit from their own JTA data sources and transaction manager support, so locating the jtaDataSource through JNDI should be your first option.
Your data source is configured with Spring:
org.springframework.jdbc.datasource.DriverManagerDataSource
and that's not really a production ready data source implementation.
So, try to configure your Spring application context to make use of the WebLogic transaction management support.
I used the information given in the answer by #Vlad Mihalcea to improve my code; however, it was not the reason it was not working. One of #Vlad's comments that suggested looking for a persistence.xml file in the META-INF folder clued me into the answer.
Even though I was using the Spring configuration file for Hibernate, I had an old persistence.xml file under the META-INF folder. I wasn't using it, but WebLogic was picking it up automatically. Since I wasn't using it, I didn't have a data source specified in the persistence.xml file. WebLogic automatically assumes any persistence unit is JTA if not specified as RESOURCE LOCAL. I deleted that persistence.xml file, and it worked.
That said, I also fixed up my code to use the JTA data source as #Vlad Mihalcea suggested. I moved all my configuration code to the Spring-servlet.xml file to simplify the configuration. I'm sure it could be translated into the programmatic Spring configuration without too much trouble.
In the meantime, here is a working JTA transaction based Spring / Hibernate configuration 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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="mil.navy.navsupbsc.entity" />
<property name="dataSource" ref="NCS"/>
<property name="jtaTransactionManager" ref="transactionManager" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.driverClassName">oracle.jdbc.OracleDriver</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
</props>
</property>
</bean>
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="mil.navy.navsupbsc" />
<tx:annotation-driven transaction-manager="transactionManager" />
<jee:jndi-lookup id="NCS" jndi-name="NCS" resource-ref="false">
</jee:jndi-lookup>
<tx:jta-transaction-manager id="transactionManager" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
Note that I also needed to add references in the web.xml and WebLogic.xml files to the JNDI data source I created on the web server (called NCS in my application).
I am getting the following exception on a Spring project.Even I tried several solutions suggested in stackoverflow I could not resolve yet. Could you please help me ?
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [springDAO.xml]
SpringDao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:amq="http://activemq.org/config/1.0"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0-SNAPSHOT.xsd"
default-autowire="autodetect">
<!-- Database -->
<bean id="ds" class="org.springframework.jndi.JndiObjectFactoryBean" autowire="no">
<property name="jndiName" value="java:comp/env/jdbc/datasource" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="ds" />
<property name="persistenceUnitName" value="NewstrackPU"/>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- tx:annotation-driven configure transactions on any beans with #Transactional, and just after the JPA transaction manager is setup. -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:component-scan base-package ="com.abc.newstrack.dao"/>
<context:component-scan base-package ="com.abc.newstrack.service"/>
Spring Dependencies
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6.SEC03</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>2.5.6.SEC03</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.5.6.SEC03</version>
</dependency>
I downloaded the activemq-core-5.0-SNAPSHOT pom.xml. It uses Spring 2.0.6 as the dependencies. I see that you have Spring 2.5.6 SEC02 as your spring dependencies.
Based on the activeMQ pom file i would believe you would have to use spring 2.0.6 as the dependencies and not 2.5.6?
As for the actual problem of your namespace not being resolved, it is generally a problem with the dependencies not being present in the classpath. In this case since active mq uses Spring 2.0.6 it isnt there in the classpath.
I have a Spring MVC application, and I was pretty confident I understand all the various configuration I have set up, however, in a recent exercise I have been switching over to use pure annotation based config (apart from the security configuration) and I have seen a change in the application's behavior which has made me think twice on a few points.
The main behavior change, is that it appears that my old app was running an OpenSessionInView type pattern - as several of my domain objects were lazy loading elements, but those elements could then still be accessed outside of the transactional/service layer classes (e.g. in my controllers) - having switched to annotations, this now fails as you would expect with lazy loading errors as the session is not open in my controller layer.
Below is the config I have been using - can any one explain which part of this is responsible for the OpenSessionInView type behavior my app was displaying previously?
App Context config file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:cloud="http://schema.cloudfoundry.org/spring" xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.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
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://schema.cloudfoundry.org/spring
http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.7.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
<context:spring-configured />
<context:annotation-config />
<mvc:annotation-driven />
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:component-scan base-package="com.tmm.enterprise.adapter"></context:component-scan>
<context:component-scan base-package="com.tmm.enterprise.service"></context:component-scan>
<context:component-scan base-package="com.tmm.enterprise.helper"></context:component-scan>
<context:component-scan base-package="com.tmm.enterprise.util"></context:component-scan>
<context:component-scan base-package="com.tmm.enterprise.repository"></context:component-scan>
<context:component-scan base-package="com.tmm.enterprise.core.dao"></context:component-scan>
<context:component-scan base-package="com.tmm.enterprise.security.dao"></context:component-scan>
<!--Http client -->
<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
<property name="state" ref="httpState" />
</bean>
<!--Http state -->
<bean id="httpState" factory-bean="httpStateFactory" factory-method="buildState"/>
<!--Http client -->
<bean id="httpClientFactory"
class="org.springframework.http.client.CommonsClientHttpRequestFactory">
<constructor-arg ref="httpClient" />
</bean>
<!--RestTemplate -->
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg ref="httpClientFactory" />
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
lazy-init="default" autowire="default">
<property name="driverClass" value="${database.driverClassName}" />
<property name="jdbcUrl" value="${database.url}" />
<property name="user" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager"
id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="applicationController" class="com.tmm.enterprise.service.ApplicationService"></bean>
<bean id="socialConfig"
class="com.tmm.enterprise.configuration.SocialConfiguration"></bean>
<bean id="cachingConfig"
class="com.tmm.enterprise.configuration.CachingConfiguration"></bean>
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager" proxy-target-class="true" />
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="persistenceUnit" />
</bean>
<bean id="geocoder" class="com.google.code.geocoder.Geocoder" />
<bean id="validatorFactory" class="javax.validation.Validation"
factory-method="buildDefaultValidatorFactory" />
<bean id="validator" factory-bean="validatorFactory"
factory-method="getValidator" />
</beans>
MVC Config:
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
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-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- The controllers are autodetected POJOs labeled with the #Controller annotation. -->
<context:component-scan base-package="com.tmm.enterprise.controller" use-default-filters="false">
<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<!-- Turns on support for mapping requests to Spring MVC #Controller methods
Also registers default Formatters and Validators for use across all #Controllers -->
<mvc:annotation-driven/>
<mvc:resources mapping="/resouces/**" location="/styles, /images, /javascript, /libs" />
<!-- a higher value meaning greater in terms of sorting. -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="3">
<property name="alwaysUseFullPath" value="true" />
</bean>
<!-- register "global" interceptor beans to apply to all registered HandlerMappings -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang"/>
</mvc:interceptors>
<!-- selects a static view for rendering without the need for an explicit controller -->
<mvc:view-controller path="/login"/>
<!--mvc:view-controller path="/index"/-->
<mvc:view-controller path="/uncaughtException"/>
<mvc:view-controller path="/resourceNotFound"/>
<mvc:view-controller path="/dataAccessFailure"/>
<mvc:view-controller path="/jobs" view-name="jobsPage"/>
<mvc:view-controller path="/applications" view-name="jobsPage"/>
<mvc:view-controller path="/users" view-name="usersPage"/>
<mvc:view-controller path="/companies" view-name="companiesPage"/>
<mvc:view-controller path="/tos" view-name="tos"/>
<mvc:view-controller path="/about" view-name="about"/>
<mvc:view-controller path="/privacypolicy" view-name="privacyPolicy"/>
<mvc:view-controller path="/sitemap.xml" view-name="sitemap"/>
<!-- Resolves logical view names returned by Controllers to Tiles; a view
name to resolve is treated as the name of a tiles definition -->
<bean class="org.springframework.js.ajax.AjaxUrlBasedViewResolver" id="tilesViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
<!-- Configures the Tiles layout system -->
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/layouts/layouts.xml</value>
<!-- Scan views directory for Tiles configurations -->
<value>/WEB-INF/views/**/views.xml</value>
</list>
</property>
</bean>
<!-- Resolves localized messages*.properties and application.properties files in the application to allow for internationalization.
The messages*.properties files translate Roo generated messages which are part of the admin interface, the application.properties
resource bundle localizes all application specific messages such as entity names and menu items. -->
<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource" p:basenames="WEB-INF/i18n/application" p:fallbackToSystemLocale="false"/>
<!-- store preferred language configuration in a cookie -->
<bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver" p:cookieName="locale"/>
<!-- resolves localized <theme_name>.properties files in the classpath to allow for theme support -->
<bean class="org.springframework.ui.context.support.ResourceBundleThemeSource" id="themeSource"/>
<!-- store preferred theme configuration in a cookie -->
<bean class="org.springframework.web.servlet.theme.CookieThemeResolver" id="themeResolver" p:cookieName="theme" p:defaultThemeName="standard"/>
<!-- This bean resolves specific types of exceptions to corresponding logical - view names for error views.
The default behaviour of DispatcherServlet - is to propagate all exceptions to the servlet container:
this will happen - here with all other types of exceptions. -->
<bean class="com.tmm.enterprise.controller.exception.NerdExceptionHandler" p:defaultErrorView="uncaughtException">
<property name="exceptionMappings">
<props>
<prop key=".DataAccessException">dataAccessFailure</prop>
<prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
<prop key=".TypeMismatchException">resourceNotFound</prop>
<prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
</props>
</property>
</bean>
<!-- Controllers -->
<bean id="connectController" class="com.tmm.enterprise.controller.ConnectController"></bean>
<!-- allows for integration of file upload functionality -->
<bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver"/>
<bean id="ajaxViewResolver"
class="com.tmm.enterprise.views.AjaxViewResolver">
<property name="ajaxView">
<bean class="com.tmm.enterprise.views.AjaxView" />
</property>
<property name="ajaxPrefix" value="ajax_"></property>
</bean>
<bean id="editableViewResolver"
class="com.tmm.enterprise.views.EditableViewResolver">
<property name="editableView">
<bean class="com.tmm.enterprise.views.EditableView" />
</property>
<property name="editablePrefix" value="editable_"></property>
</bean>
</beans>
The OpenSessionInView(Hibernate)/OpenEntityManagerInView(JPA) behaviour is often part of a filter defined in web.xml, but can also be done using an interceptor, as described in this answer. You can use the OpenEntityManagerInViewInterceptor for JPA.
<mvc:interceptors>
<bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
</mvc:interceptors>
I'm trying to use util-constant for ioc but I'm getting the following error message:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'util:constant'.
All of the spring 3.1.1 dist jars are in my classpath and I was able to successfully run my program prior to making the changes that included the use of the util:constant tag.
Here's my ioc xml file:
<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:tool="http://www.springframework.org/schema/tool"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:config.properties</value>
</property>
</bean>
<bean id="main" class="pikefin.Main">
<property name="executorSample" ref="executorSample"/>
</bean>
<bean id="executorSample" class="pikefin.ExecutorSample">
<constructor-arg ref="threadPoolExecutor" />
</bean>
<bean id="threadPoolExecutor" class="java.util.concurrent.ThreadPoolExecutor">
<constructor-arg index="0" value="2"/>
<constructor-arg index="1" value="2"/>
<constructor-arg index="2" value="10"/>
<constructor-arg index="3"><util:constant static-field="java.util.concurrent.TimeUnit.SECONDS"/></constructor-arg>
<constructor-arg index="4" ref="arrayBlockingPool"/>
</bean>
<bean id="arrayBlockingPool" class="java.util.concurrent.ArrayBlockingQueue">
<constructor-arg value="5"/>
</bean>
</beans>
This is the correct declaration of util namespace (don't forget about specifying schemaLocation):
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
</beans>
See more at C.2.2 The util schema.