Error creating bean with name 'messageSource': Injection of autowired dependencies failed; - spring

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource':
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private xx.services.MessageSourceService xx.controllers.DatabaseDrivenMessageSource.messageSourceService;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSourceService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private xx.dao.MessageSourceDAO xx.services.MessageSourceService.messageSourceDao;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSourceDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory
xx.dao.MessageSourceDAO.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NullPointerException
APPLICATION CONTEXT.XML
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<property name="packagesToScan" value="com.abc.cmtglobal"></property>
</bean>
<context:annotation-config />
<bean id="messageSource" class="com.abc.cmtglobal.controllers.DatabaseDrivenMessageSource"></bean>
<context:component-scan base-package="com.abc.cmtglobal" >

The root cause is
Error creating bean with name 'sessionFactory' defined in class path
resource [applicationContext.xml]
So it looks like you are having a problem with your hibernate configuration.
The last line of your stacktrace shows a NullPointerException.
In eclipse or InteliJ you can set Exception breakpoints.
Set one for NullPointerException and debug the startup. You may see some NullPointerExceptions not related to your problem, but finally you will see the one that is terminating startup. Once you found the location where it happens its mostly easy to find a solution..

Related

500 error -- CannotLoadBeanClassException

I am getting a 500 error from my Spring web application. The mentioned files are correctly named and in the correct packages. Here is the error message.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.dao.CommentDAO] for bean with name 'commentDAO' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.dao.CommentDAO
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.dao.CommentDAO] for bean with name 'commentDAO' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.dao.CommentDAO
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.controller.PagesController] for bean with name 'pagesController' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.controller.PagesController
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.controller.CommentController] for bean with name 'commentController' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.controller.CommentController
Here is the relevant portion of ghs1986-servlet.xml.
<bean id="commentDAO" class="com.dao.CommentDAO">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="pagesController" class="com.controller.PagesController" />
<bean id="commentController" class="com.controller.CommentController">
<property name="commentDAO" ref="commentDAO" />
</bean>
Problem solved. I needed the #Component annotation on CommentDAO.

BeanCreationException:Error creating bean

mvc-dispatcher-servlet.xml
<bean class="com.springframework.BlogController">
<property name="formView" value="Welcome" />
<property name="successView" value="Home" />
<!-- Mapping validator -->
<property name="validator">
<bean class="com.springframework.BloggerValidator" />
</property>
Error:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.springframework.BlogController] for bean with name 'com.springframework.BlogController#0' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.springframework.BlogController
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.springframework.BlogController] for bean with name 'com.springframework.BlogController#0' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.springframework.BlogController
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
Cannot find class [com.springframework.BlogController] for bean with name 'com.springframework.BlogController'
No class called com.springframework.BlogController on your webapp's classpath.
Check if the qualified classname is correct in /WEB-INF/"*".xml
Or, check if /WEB-INF/classes directory in missing.

creating custom ItemReader with defaultLineMapper using spring annotations

I am trying to make a annotation based ItemReader in spring-batch. I was able to make the desired ItemReader in my xml but annotation based is not at all working giving the following error:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'runScheduler': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.Job com.techavalanche.batch.RunScheduler.job; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportJob': Cannot create inner bean '(inner bean)#3f9bb1' of type [org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean] while setting bean property 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f9bb1': Cannot create inner bean '(inner bean)#17e6f05' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#17e6f05': Cannot create inner bean '(inner bean)#66da50' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#66da50': Cannot resolve reference to bean 'step1' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'customItemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customItemReader': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.springframework.batch.item.file.FlatFileItemReader com.techavalanche.reader.CustomReader.itemReader; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getFlatFileItemReader' defined in class path resource [com/techavalanche/reader/CustomReader.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: LineMapper is required
and it is caused by :
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.Job com.techavalanche.batch.RunScheduler.job; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportJob': Cannot create inner bean '(inner bean)#3f9bb1' of type [org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean] while setting bean property 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f9bb1': Cannot create inner bean '(inner bean)#17e6f05' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#17e6f05': Cannot create inner bean '(inner bean)#66da50' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#66da50': Cannot resolve reference to bean 'step1' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'customItemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customItemReader': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.springframework.batch.item.file.FlatFileItemReader com.techavalanche.reader.CustomReader.itemReader; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getFlatFileItemReader' defined in class path resource [com/techavalanche/reader/CustomReader.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: LineMapper is required
My CustomReader is
package com.techavalanche.reader;
#Component("customReader")
public class CustomReader implements ItemReader<Report> {
#Autowired
public FlatFileItemReader<Report> itemReader;
#Bean
public FlatFileItemReader getFlatFileItemReader(){
return new FlatFileItemReader();
}
#Bean
public DefaultLineMapper getDefaultLineMapper(){
return new DefaultLineMapper();
}
#Autowired
public DefaultLineMapper<Report> lineMapper;
#Bean
public FixedLengthTokenizer getLinetokenizer(){
return new FixedLengthTokenizer();
}
#Autowired
public FixedLengthTokenizer linetokenizer;
#Bean
public BeanWrapperFieldSetMapper getBeanWrapperFieldSetMapper() {
return new BeanWrapperFieldSetMapper();
}
#Autowired
public BeanWrapperFieldSetMapper<Report> fieldSetMapper;
public Resource res=new FileSystemResource("D:\\testresource\\report.csv");
String[] names= {"date","impressions","clicks","earning"};
#Override
public Report read() throws Exception, UnexpectedInputException, ParseException,
NonTransientResourceException {
for(String name:names){
System.out.println(name);
}
linetokenizer.setNames(new String[] {"date","impressions","clicks","earning"});
Range range1=new Range(1,12);
Range range2=new Range(13,15);
Range range3=new Range(16,20);
Range range4=new Range(21,28);
Range[] ranges={range1,range2,range3,range4};
linetokenizer.setColumns(ranges);
lineMapper.setLineTokenizer(linetokenizer);
fieldSetMapper.setPrototypeBeanName("report");
lineMapper.setFieldSetMapper(fieldSetMapper);
itemReader.setResource(res);
itemReader.setLineMapper(lineMapper);
itemReader.open(new ExecutionContext());
Report report= itemReader.read();
return report;
}
}
My Xml Configuration looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
">
<context:component-scan base-package="com.techavalanche" />
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="report" class="com.techavalanche.batch.Report" scope="prototype" />
<bean id="customWriter" class="com.techavalanche.writer.CustomWriter" />
<batch:job id="reportJob">
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="customItemReader" writer="customWriter"
commit-interval="2">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="file:D:\testresource\report.csv" />
<property name="delegate" ref="cvsFileItemReader" />
</bean>
<bean id="customItemReader" class="com.techavalanche.reader.CustomReader" />
<bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<!-- Read a csv file -->
<!-- <property name="resource" ref="resource" /> -->
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<!-- split it -->
<property name="lineTokenizer">
<bean id="fixedLengthLineTokenizer"
class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
<property name="names" value="date,impressions,clicks,earning" />
<property name="columns" value="1-12,13-15,16-20,21-28" />
</bean>
</property>
<property name="fieldSetMapper">
<!-- return back to reader, rather than a mapped object. -->
<!-- <bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper"
/> -->
<!-- map to an object -->
<bean
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="prototypeBeanName" value="report" />
</bean>
</property>
</bean>
</property>
</bean>
</beans>

Spring, Hibernate with google app engine

Project Name: CarpoolDB, I have added the jar for this project in another application name Carpool.
While running the Carpool app I am getting following exception.
Project: Carpool.
Here i am getting exception as "carpoolService" not getting autowired while running as "Google Web application" but same runs under Tomcat and beans properly get injected.
#Controller
public class PlacesSearchController {
#Autowired
CarpoolService carpoolService=null;
public CarpoolService getCarpoolService() {
return carpoolService;
}
public void setCarpoolService(CarpoolService carpoolService) {
this.carpoolService = carpoolService;
}
}
carpool-application-context1.xml
Also I have applicationContext-security.xml, for spring security.
Project: CarpoolDB
All class are in package, com.company.carpooldb.db
public interface CarpoolService {
public boolean validateUser(User user);
}
#Service("carpoolService")
public class CarpoolServiceImpl implements CarpoolService{
#Autowired
private CarpoolDao carpoolDao=null;
public CarpoolDao getCarpoolDao() {
return carpoolDao;
}
public void setCarpoolDao(CarpoolDao carpoolDao) {
this.carpoolDao = carpoolDao;
}
#Override
public boolean validateUser(User user) {
return carpoolDao.validateUser(user);;
}
}
public interface CarpoolDao {
public boolean validateUser(User user);
}
public class CarpoolDaoImpl extends HibernateDaoSupport implements CarpoolDao{
#Override
public boolean validateUser(User user) {
// TODO Auto-generated method stub
return false;
}
}
carpool-application-context.xml
<context:annotation-config />
<context:component-scan base-package="com.onmobile" />
<context:property-placeholder location="classpath:server.properties" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>com\company\carpooldb\hbm\User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"><!--Which dialect is used of hibernate according to type of underlying database-->
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName"><beans:value>${cm.db.driverClassName}</beans:value></beans:property>
<beans:property name="url"><beans:value>${cm.db.url}</beans:value></beans:property>
<beans:property name="username"><beans:value>${cm.db.username}</beans:value></beans:property>
<beans:property name="password"><beans:value>${cm.db.password}</beans:value></beans:property>
<beans:property name="testOnBorrow"><beans:value>true</beans:value></beans:property>
<beans:property name="testOnReturn"><beans:value>true</beans:value></beans:property>
<beans:property name="validationQuery"><beans:value>select 1</beans:value></beans:property>
</beans:bean>
<!--Hibernate's transaction manager used for handling database transactions/manipulating data happening-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="carpoolDaoImpl" class="com.company.carpooldb.db.CarpoolDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
While running the application, I am getting exception as,
log4j:WARN Error during default initialization
java.lang.NoClassDefFoundError: java.io.FileOutputStream is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
.........
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:162)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
11 Nov, 2012 5:14:18 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Failed startup of context com.google.apphosting.utils.jetty.DevAppEngineWebAppContext#5e55ab{/,D:\EclipseEuropa\CarpoolingGAE\war}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'placesSearchController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.onmobile.carpooldb.db.CarpoolService com.onmobile.carpool.controller.PlacesSearchController.carpoolService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
.........
at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.onmobile.carpooldb.db.CarpoolService com.onmobile.carpool.controller.PlacesSearchController.carpoolService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
... 31 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
.... at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:780)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 33 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
... 44 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
.... at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 46 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
.... at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 59 more
Caused by: java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
.... at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1457)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
... 66 more
11 Nov, 2012 5:14:18 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'placesSearchController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.onmobile.carpooldb.db.CarpoolService com.onmobile.carpool.controller.PlacesSearchController.carpoolService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.:
java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.hibernate.id.AbstractUUIDGenerator.<clinit>(AbstractUUIDGenerator.java:22)
......at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
.....
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
..... at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
The server is running at http://localhost:8888/
Why I am getting as
1. java.lang.NoClassDefFoundError: java.io.FileOutputStream is a restricted class.
I am not writing anything on file
GAE doesn't support few API that I am aware of but my application already working for MySQL and I want to support both. I mean based on property set in my property file I want to use sometime MySQL and sometime want to work with GAE datastore.
I am using spring 3.
What I should do in this case?
As Boris notes, the issue appears to be with your session factory. GAE doesn't support jdbc, and it looks like your sessionFactory is configured for mysql:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"><!--Which dialect is used of hibernate according to type of underlying database-->
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
If you're working with an existing codebase that depends on Hibernate, you could try configuring Hibernate to run backed by Cloud SQL: https://developers.google.com/appengine/articles/using_hibernate
As for the FileOutputStream issue, I believe one of the default appenders for log4j is a FileAppender, so simply not configuring log4j won't fix it - you'll need to explicitly configure it. See if this page helps: http://blog.xam.de/2010/03/logging-in-google-appengine-for-java.html

Error Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.connection.C3P0ConnectionProvider]

I have an error in Hibernate 4.1.2.FINAL, JBoss 7.1.1,and Spring 3.1.0.RELEASE,like this:
12:10:50,853 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-2)
Context initialization failed: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'departamentoDao' defined in URL [vfs:/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war/WEB-INF/classes/META-INF/spring/spring-hibernate.xml]:Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'hibernateTemplate' defined in URL [vfs:/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war/WEB-INF/classes/META-INF/spring/spring-hibernate.xml]:
Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in URL [vfs:/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war/WEB-INF/classes/META-INF/spring/spring-hibernate.xml]:
Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
Caused by:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'hibernateTemplate' defined in URL
[vfs:/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war/WEB-INF/classes/META-INF/spring/spring-hibernate.xml]:
Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in URL
[vfs:/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war/WEB-INF/classes/META-INF/spring/spring-hibernate.xml]:
Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
and :
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in URL [vfs:/opt/jboss-as-7.1.1.Final/standalone/deployments/projvehimerc.war/WEB-INF/classes/META-INF/spring/spring-hibernate.xml]: Invocation of init method failed; nestwared exception is org.hibernate.service.spi.ServiceException:
Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
>>Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service
>>Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.connection.C3P0ConnectionProvider]
and my spring-hibernate configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
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.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- Hibernate SessionFactory -->
<bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="vehicDataSource">
<!-- p:lobHandler-ref="defaultLobHandler"-->
<property name="annotatedClasses">
<list>
<!-- Procedimientos -->
<value>com.reglamb.projvehimerc.domain.HabilitacionVehicular_Inscripcion</value>
<!-- Main Properties -->
<value>com.reglamb.projvehimerc.domain.Transportista</value>
<value>com.reglamb.projvehimerc.domain.Ubigeo</value>
<value>com.reglamb.projvehimerc.domain.TransportistaNatural</value>
<value>com.reglamb.projvehimerc.domain.TransportistaJuridico</value>
<value>com.reglamb.projvehimerc.domain.Conductor</value>
<!-- Transportista's Ubigeo -->
<value>com.reglamb.projvehimerc.domain.ubigeo.Departamento</value>
<value>com.reglamb.projvehimerc.domain.ubigeo.Distrito</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=${hibernate.dialect}
hibernate.default_schema=${hibernate.default_schema}
hibernate.jdbc.batch_size=${hibernate.jdbc.batch_size}
hibernate.c3p0.max_size=${hibernate.c3p0.max_size}
hibernate.c3p0.min_size=${hibernate.c3p0.min_size}
hibernate.c3p0.timeout=${hibernate.c3p0.timeout}
hibernate.c3p0.max_statements=${hibernate.c3p0.max_statements}
hibernate.c3p0.idle_test_period=${hibernate.c3p0.idle_test_period}
hibernate.c3p0.acquire_increment=${hibernate.c3p0.acquire_increment}
<!--hibernate.c3p0.validate=${hibernate.c3p0.validate}-->
<!--hibernate.cache.provider_class=${hibernate.cache.provider_class}-->
hibernate.connection.provider_class=${hibernate.connection.provider_class}
hibernate.show_sql=${hibernate.show_sql}
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
hibernate.id.new_generator_mappings=${hibernate.id.new_generator_mappings}
<!-- Auto Generated Schemas and tables not good for production
hibernate.hbm2ddl.auto=update-->
<!--hibernate.cache.use_second_level_cache=true-->
<!--hibernate.cache.use_query_cache=true-->
</value>
</property>
</bean>
<!-- Transaction Config -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory"/>
<!-- Hibernate Template -->
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate"
p:sessionFactory-ref ="sessionFactory"/>
<!-- Injectores Procedimiento -->
<bean id="inscriptransportistaDao"
class="com.reglamb.projvehimerc.dao.hibernate.HabilitacionVehicular_InscripcionDaoHibernate" >
<property name="hibernateTemplate" ref ="hibernateTemplate" />
</bean>
<!-- Injectores Ubigeo -->
<bean id="ubigeoDao"
class="com.reglamb.projvehimerc.dao.hibernate.UbigeoDaoHibernate" >
<property name="hibernateTemplate" ref ="hibernateTemplate" />
</bean>
<bean id="departamentoDao"
class="com.reglamb.projvehimerc.dao.hibernate.ubigeo.DepartamentoDaoHibernate" >
<property name="hibernateTemplate" ref ="hibernateTemplate" />
</bean>
<bean id="distritoDao"
class="com.reglamb.projvehimerc.dao.hibernate.ubigeo.DistritoDaoHibernate" >
<property name="hibernateTemplate" ref ="hibernateTemplate" />
</bean><
<bean name="inscripcionHabilitacionVehicFacade" class="com.reglamb.projvehimerc.service.HabilitacionVehicular_InscripcionFacadeImpl" />
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
What's the error ? thnks.
It looks like you set hibernate.connection.provider_class to org.connection.C3P0ConnectionProvider.
It should be org.hibernate.connection.C3P0ConnectionProvider instead.

Resources