this is error:
WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'totalCustomersDao' defined in class path resource [trainingcore-spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'modelService' of bean class [de.hybris.training.core.dao.impl.TotalCustomersDaoImpl]: Bean property 'modelService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? WARN [localhost-startStop-1] [CloseAwareApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'totalCustomersDao' defined in class path resource [trainingcore-spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'modelService' of bean class [de.hybris.training.core.dao.impl.TotalCustomersDaoImpl]: Bean property 'modelService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? ERROR [localhost-startStop-1] [HybrisContextFactory] Error initializing global application context! org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'totalCustomersDao' defined in class path resource [trainingcore-spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'modelService' of bean class [de.hybris.training.core.dao.impl.TotalCustomersDaoImpl]: Bean property 'modelService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
trainingcore.spring.xml
<!-- Total Customer service dao facade-->
<alias alias="totalCustomersDao" name="totalCustomersDao"/>
<bean id="totalCustomersDao"
class="de.hybris.training.core.dao.impl.TotalCustomersDaoImpl"
parent="abstractItemDao" >
<property name="flexibleSearchService" ref="flexibleSearchService"/>
</bean>
<bean id="totalCustomerService"
class=" de.hybris.training.core.impl.TotalCustomerServiceImpl" >
<property name="totalCustomersDao" ref="totalCustomersDao"/>
</bean>
<bean id="totalCustomerFacade" class="de.hybris.training.core.facade.impl.TotalCustomerFacadeImpl">
<property name="totalCustomerService" ref="totalCustomerService"/>
</bean>
TotalCustomersDaoImpl
public class TotalCustomersDaoImpl implements TotalCustomersDao { private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UsersFindJob.class);
private static final String query =
"SELECT *" +
"FROM {" + CustomerModel._TYPECODE + "}"+
"WHERE p_name LIKE "
+ "'%" + CustomerModel.NAME+"+%'";
private DefaultFlexibleSearchService flexibleSearchService;
public List<CustomerModel> findAllCustomersFromDao(String name) {
LOG.info("***********************************");
LOG.info("***********************************");
LOG.info("*************************findAllCustomersFromDao**********");
LOG.info("***********************************");
LOG.info("***********************************");
final Map<String, Object> params = new HashMap<String, Object>();
params.put(CustomerModel.NAME, name);
FlexibleSearchQuery fQuery = new FlexibleSearchQuery(query);
if (params != null) {
fQuery.addQueryParameters(params);
}
final SearchResult<CustomerModel> result = flexibleSearchService.search(fQuery);
return result.getResult();
}
public void setFlexibleSearchService(DefaultFlexibleSearchService flexibleSearchService) {
this.flexibleSearchService = flexibleSearchService;
}
public DefaultFlexibleSearchService getFlexibleSearchService() {
return flexibleSearchService;
}
}
TotalCustomerFacadeImpl
public class TotalCustomerFacadeImpl implements TotalCustomerFacade {
//TODO autowired or resoucre not work
private TotalCustomerService totalCustomerService; private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UsersFindJob.class);
public TotalCustomerService getTotalCustomerService() {
return totalCustomerService;
}
public void setTotalCustomerService(TotalCustomerService totalCustomerService) {
this.totalCustomerService = totalCustomerService;
}
@Override
public List<String> findCustomerContainingName(String firstName) {
List<CustomerModel> customerModels;
List<String> customerFirstNames = new ArrayList<>();
LOG.info("***********************************");
LOG.info("***********************************");
LOG.info("*************************findCustomerContainingName**********");
LOG.info("***********************************");
LOG.info("***********************************");
customerModels = totalCustomerService.getAllCustomersNames(firstName);
LOG.info("***********************************");
LOG.info("***********************************");
LOG.info("*************************2findCustomerContainingName**********");
LOG.info("***********************************");
LOG.info("***********************************");
for (int i = 0; i < customerModels.size(); i++) {
final String fName = splitName(customerModels.get(i).getName())[0];
customerFirstNames.add(fName);//adding first name
}
return customerFirstNames;
}
TotalCustomerServiceImpl
public class TotalCustomerServiceImpl implements TotalCustomerService {
private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UsersFindJob.class);
private TotalCustomersDao totalCustomersDao;
public TotalCustomersDao getTotalCustomersDao() {
return totalCustomersDao;
}
public void setTotalCustomersDao(TotalCustomersDao totalCustomersDao) {
this.totalCustomersDao = totalCustomersDao;
}
The error says Bean property 'modelService' is not writable or has an invalid setter method.
I haven't used modelservice
.
For Dao and service class, I have true names in XML and JAVA. in IntelliJ idea when I click on XML, I can go to java class where I expect to go.
The problem is, you have declared parent="abstractItemDao"
for totalCustomersDao
in your XML, on the other side you haven't implemented AbstractItemDao
class.
In another word, your class doesn't have any modelService property which actually defined in your XML bean definition and it leads to NotWritablePropertyException for modelService
Either you can remove parent="abstractItemDao"
from your totalCustomersDao
declaration if you at all don't want to use anything from AbstractItemDao class.
<alias alias="totalCustomersDao" name="totalCustomersDao"/>
<bean id="totalCustomersDao"
class="de.hybris.training.core.dao.impl.TotalCustomersDaoImpl">
<property name="flexibleSearchService" ref="flexibleSearchService"/>
</bean>
Or
extends AbstractItemDao
class in TotalCustomersDaoImpl
public class TotalCustomersDaoImpl extends AbstractItemDao implements TotalCustomersDao