New to spring. I'm getting the following exception being caught:
2012-06-14 16:20:57,719 [http-8080-6] ERROR com.nimchip.lmu.data.service.impl.CoworkerServiceImpl - Error sending mail:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp. Failed messages: javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:400) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) ~[spring-context-support-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at com.nimchip.lmu.data.service.impl.CoworkerServiceImpl.genUpdateNomination(CoworkerServiceImpl.java:224) ~[lmu-dataaccess-1.0.0.jar:na]
at com.nimchip.lmu.controller.coworkerNom.CoworkerController.genUpdateNomination(CoworkerController.java:312)
I have a mail-config.xml which is registered in my web.xml. Here it is:
<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.5.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="10.30.137.190"/>
<property name="port" value="25"/>
</bean>
</beans>
I should be able to log anonymously to the mail server specified, so no user or password needed.
What am I missing?
Do you have the mail.jar and activation.jarin your classpath?
These classes should provide the smtp-provider.
If you are using maven, simply add this to your pom:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.0.2</version>
</dependency>
I had the same problem. I was using mailapi as artifact id and that was causing the issue.
I replaced
<artifactId>mailapi</artifactId> with
<artifactId>mail</artifactId> and it worked fine
Related
I am working on a project in spring boot and I need to add Spring integration poller for polling files from a location and run spring batch on that file to process it.
I have used spring batch integration for this(Document Reference below.)
http://docs.spring.io/spring-batch/trunk/reference/html/springBatchIntegration.html
In spring boot, I have succesfully configured my poller in #Configuration file as below
#Bean
#InboundChannelAdapter(value = "fileInputChannel", poller = #Poller(
fixedRate = "1000"), autoStartup = "true")
public MessageSource<File> filesScanner() {
CompositeFileListFilter<File> filters = new CompositeFileListFilter<File>();
filters.addFilter(new SimplePatternFileListFilter("*.xml"));
filters.addFilter(new AcceptOnceFileListFilter<File>());
filters.addFilter(getLastModifiedFileFilter());
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File("F:/DataInput/"));
source.setFilter(filters);
return source;
}
This poller is defined in java configuration whereas the channels are defined in xml as below.
<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
<int:channel id="ticketingResponse" />
<int:channel id="mailFailureTicketData" />
<int:channel id="moveSuccessTicketingFile" />
<int:channel id="moveFailureTicketingFile" />
<int:channel id="ticketingFileInput" />
<int:channel id="ticketingJobParameters" />
<!-- <int-file:inbound-channel-adapter id="filePoller"
channel="inboundFileChannel"
directory="file:/tmp/myfiles/"
filename-pattern="*.csv">
<int:poller fixed-rate="1000"/>
</int-file:inbound-channel-adapter> -->
<bean id="earliestTicketingFileSelecter" class="com.avios.integration.iqcx.FilesSortingComparator" />
<bean id="compositeFilesFilter"
class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean
class="org.springframework.integration.file.filters.RegexPatternFileListFilter">
<constructor-arg name="pattern" value="${ticketing.input.file.pattern}" />
</bean>
<bean class="org.springframework.integration.file.filters." />
<bean
class="org.springframework.integration.file.filters.LastModifiedFileListFilter">
<property name="age" value="${ticketing.input.file.age}" />
</bean>
</list>
</constructor-arg>
</bean>
<bean id="ticketingFilesScanner"
class="org.springframework.integration.file.FileReadingMessageSource">
<property name="filter" value="compositeFilesFilter" />
<property name="directory" value="/tmp/myfiles/" />
</bean>
<int-file:inbound-channel-adapter id="filePoller"
channel="inboundFileChannel"
directory="file:/tmp/myfiles/"
filename-pattern="*.csv">
<int:poller fixed-rate="1000"/>
</int-file:inbound-channel-adapter><!-- <int-file:inbound-channel-adapter
directory="${ticketing.input.file.path}" channel="ticketingFileInput"
comparator="earliestTicketingFileSelecter" auto-startup="true" filter="compositeFilesFilter" >
<int:poller ></int:poller>
</int-file:inbound-channel-adapter> -->
<int:transformer id="iqcxFilesToJobParameters" ref="jobParameterTransformer"
input-channel="ticketingFileInput" method="addTicketingFileToJobParameter"
output-channel="ticketingJobParameters" />
<int:outbound-channel-adapter channel="ticketingJobParameters"
ref="iqcxJobLaunchingGateway" method="handleMessage" />
</beans>
I am getting the below error in my XML configuration file.
cvc-complex-type.3.2.2: Attribute 'fixed-rate' is not allowed to appear in element 'int:poller'.
I checked this on google and found only the below link which wasn't much of use as i am getting exact same error.
Using Spring Boot & Spring Integration with database backed Configuration
Attribute 'fixed-rate' is not allowed to appear in element 'int:poller'
Spring boot version i am using is as below.
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
Spring integration jar in library - Spring-integration-core-4.2.8.RELEASE.jar
I also tried excluding integration jar from batch-integration dependency and adding it separately as below but that didn't work either.
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-integration</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.integration/spring-integration-core -->
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</dependency>
Also checked the XSD http://www.springframework.org/schema/integration/spring-integration.xsd and it has the attribute fixed-delay in poller. Any suggestions for resolving this?
Read the important note in the online schema:
+++++ IMPORTANT +++++
This schema is for the 1.0 version of Spring Integration Core. We cannot update it to the current schema
because that will break any applications using 1.0.3 or lower. For subsequent versions, the unversioned
schema is resolved from the classpath and obtained from the jar.
Please refer to github:
https://github.com/spring-projects/spring-integration/tree/master/spring-integration-core/src/main/resources/org/springframework/integration/config/xml
for the latest schema.
In the old schema, fixed-rate was part of a periodic trigger child element on the poller.
The 4.2 schema is here.
If this is just an IDE error, you can ignore it, or configure your IDE to be "spring aware".
Spring finds the actual schema on the classpath.
With STS, enable "spring nature" on the project.
sometimes it could be due to missing spring-boot-starter-integration & spring-integration-file dependency in pom.xml. So check if actually spring-integration-file dependency is available in your project when you are using spring integration.
I am creating an application to upload a file from browser. The web service client was build using the spring SaajSoapMessageFactory. Using websphere.
pom.xml
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3.16</version>
<scope>provided</scope>
</dependency>
dispatcher-servlet.xml
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="messageFactory">
<bean class="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl" />
</property>
</bean>
The spring web service throws the following exception during the file upload.
Exception created : [org.springframework.ws.soap.saaj.SaajSoapMessageException: Could not write message to OutputStream: Error during saving a multipart message; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
at org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:251)
at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:45)
My XML file looks like this
<mongo:mongo host="${mongo.host}" port="${mongo.port}"/>
<mongo:db-factory dbname="SmartSearch" mongo-ref="mongo" username="${mongo.user}" password="${mongo.password}"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
<mongo:repositories base-package="be.omniatravel.service.repository"/>
I have the latest dependency for MongoDB in maven
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.0.RELEASE</version>
</dependency>
It connects properly on the startup of my Tomcat server, but when i try to interact with the db i get the following error
HTTP Status 500 - Request processing failed; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [MY_DATABASE], username = [MY_USERNAME], password = [MY_PASSWORD]
I made sure the db, user and password are correct.
The code in my question was correct.
The problem was that the server admin changed the database name from SmartSearch to SmartSearchDev.
I have been struggling with that error for long time, have googled, looked at the examples around the web and still not getting to work. To be honest I don't understand why my project throws this error.
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.oxm.Marshaller] for property 'marshaller': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:264)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448)
... 52 more)
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.TestCase.fail(TestCase.java:227)
at junit.framework.TestSuite$1.runTest(TestSuite.java:100)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
So my setup is Spring Web Services, Jaxb2, maven. I have predefined xsd files and generated java classes from them by jaxb2 maven plugin.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>schema1-xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/</schemaDirectory>
<schemaFiles>ApplicationResponse.xsd</schemaFiles>
<packageName>com.package.response</packageName>
</configuration>
</execution>
</executions>
</plugin>
My pom has additionally these dependencies:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.api.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.7</version>
<!-- <exclusions>
<exclusion>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</exclusion>
</exclusions> -->
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.stream</groupId>
<artifactId>sjsxp</artifactId>
<version>1.0.2</version>
</dependency>
Here is my appContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<context:component-scan base-package="com.package" />
<sws:annotation-driven />
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_11" />
</property>
</bean>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory"/>
<property name="defaultUri" value="https://example/address/hidden"/>
<property name="marshaller" value="marshaller" />
<property name="unmarshaller" value="marshaller" />
</bean>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.package.request:com.package.request" />
</bean>
</beans>
My service client class
#Component
public class NorServiceClient implements NorService {
#Autowired
private WebServiceTemplate wsTemplate;
public void setDefaultUri(String defaultUri) {
wsTemplate.setDefaultUri(defaultUri);
}
public ApplicationResponse downloadFileList(ApplicationRequest request) {
// Command: DownloadFileList
return (ApplicationResponse) wsTemplate.marshalSendAndReceive(request);
}
}
And my test case:
public class AppTest extends TestCase {
private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/appContext.xml");
#Test
public void testApplicationRequest() {
assertNotNull(new Object());
System.out.println("Context: " + context);
NorService norService = (NorService) context.getBean("norServiceClient");
ApplicationRequest request = new ApplicationRequest();
nordeaService.downloadFileList(request);
}
}
When launching my app it doesn't even get to the service.downloadFileList, it throws the exception when initializing context. So I don't think it may be the problem that I have instatiated just empty ApplicationRequest object.
Where could the problem lie? By all the examples in the internet I have done setup the same way, but in my project it throws the exception that no matching editors or conversion strategy found
I assume your error refers to this
<property name="marshaller" value="marshaller" />
The property marshaller refers to a field of type org.springframework.oxm.Marshaller of the class org.springframework.ws.client.core.WebServiceTemplate. You can't give it a String value of "marshaller".
You want to reference another bean in the context with the id marshaller.
<property name="marshaller" ref="marshaller" />
Same thing for your unmarshaller.
I am trying to include spring and hibernate in an application running on a Weblogic 10.3 server. When I run the application in the server, while accessing an TestServlet to check my configuration I get the following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [spring-config/HorizonModelPeopleConnectionsSpringContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:448)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:91)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:75)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:65)
at view.com.horizon.test.SpringHibernateServlet.doGet(SpringHibernateServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.wls.filter.SSOSessionSynchronizationFilter.doFilter(SSOSessionSynchronizationFilter.java:279)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:326)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:756)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:721)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:384)
... 31 more
Caused by: java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:158)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.(LocalSessionFactoryBean.java:158)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85)
... 35 more
I have checked my application and the hibernate jar file is included and it contains the class it says its missing: org.hibernate.cfg.Configuration.
The application is built with maven. These are the dependencies of the JAR file using spring and hibernate:
<!-- Frameworks -->
<!-- Hibernate framework -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.7.ga</version>
</dependency>
<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.2</version>
</dependency>
<!-- Hibernate gives you a choice of bytecode providers between cglib and javassist -->
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.4.GA</version>
</dependency>
<!-- Spring framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>2.5.6</version>
</dependency>
At first I thought it could be an issue with the versions in the spring and hibernate libraries, so I have tried with different ones, but still I couldn't find anywhere where it says which library versions are compatible,. just got that Spring 2.5.x needs hibernate >=3.1
And this is my Spring 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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="myDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/WebCenterDS</value>
</property>
<!--property name="resourceRef">
<value>true</value>
</property>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://localhost:7001</prop>
</props>
</property-->
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="configLocation">
<value>classpath:hibernate-config/hibernate.cfg.xml</value>
</property>
<property name="mappingResources">
<list>
<value>classpath:com/horizon/model/peopleconnections/profile/internal/bean/CustomAttribute.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
</property>
</bean>
<bean id="profileExtensionDAO"
class="com.horizon.model.peopleconnections.profile.internal.dao.ProfileExtensionDAOImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
</beans>
The WAR structure I get is the following:
J2EETestApplication
│ springhibernate.jsp
│
└───WEB-INF
│ faces-config.xml
│ web.xml
│ weblogic.xml
│
├───classes
│ └───view
│ └───com
│ └───horizon
│ └───test
│ SpringHibernateServlet.class
│
└───lib
activation-1.1.jar
antlr-2.7.6.jar
aopalliance-1.0.jar
asm-1.5.3.jar
asm-attrs-1.5.3.jar
cglib-2.1_3.jar
commons-codec-1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
hibernate-3.2.7.ga.jar
horizon-model-commons-1.0-SNAPSHOT.jar
horizon-model-peopleconnections-1.0-SNAPSHOT.jar
horizon-shared-commons-1.0-SNAPSHOT.jar
horizon-shared-logging-1.0-SNAPSHOT.jar
horizon-shared-util-1.0-SNAPSHOT.jar
horizon-shared-webcenter-1.0-SNAPSHOT.jar
horizon-shared-webcenter.jar
httpclient-4.0.1.jar
httpcore-4.0.1.jar
javassist-3.4.GA.jar
jta-1.0.1B.jar
log4j-1.2.14.jar
mail-1.4.1.jar
peopleconnections-profile-model-11.1.1.2.0.jar
saxon-9.1.0.8.jar
serviceframework-11.1.1.2.0.jar
slf4j-api-1.5.2.jar
slf4j-log4j12-1.5.2.jar
spring-beans-2.5.6.jar
spring-context-2.5.6.jar
spring-core-2.5.6.jar
spring-orm-2.5.6.jar
spring-tx-2.5.6.jar
Is there any dependency or configuration I am missing?
If I use hibernate without spring using (with the same libraries) I don't get the ClassDefNotFoundException:
import java.net.URL;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
URL hibernateConfigURL = HibernateUtil.class.getClassLoader().getResource("hibernate-config/hibernate.cfg.xml");
return new Configuration().configure(hibernateConfigURL).buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
That makes me think that is not a problem with the hibernate library not being properly picked. The Spring libraries seem to be picked properly as it starts to build the beans from the ApplicationContent. Could it be an issue of these two libraries not seeing each other?
My guess is that your application is not using the Spring JARs inside the webapp but the one provided by WebLogic and those can't "see" the Hibernate JAR inside the war.
To tell Weblogic to look into the war file, provide a WEB-INF/weblogic.xml with prefer-web-inf-classes set to true (this is required for Hibernate anyway because of the ANTLR version bundled in WLS):
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<context-root>/myApp</context-root>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
You have missed the hibernate-core dependency...example in the docs.
http://docs.jboss.org/hibernate/stable/core/reference/en/html/tutorial.html#tutorial-firstapp-mvn
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
i had compile 'org.hibernate:hibernate-core:4.1.9'
i replaced it with compile 'org.hibernate:hibernate-core:3.3.2.GA'
this is gradle syntax, converting to maven isnt difficult
In addition to your answer #Rafeeq, this did the trick should incase you are using Maven dependency on pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>