daos-services 的 hybris 错误
Error on hybris for daos-services
这是错误:
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;
}
错误显示 Bean property 'modelService' is not writable or has an invalid setter method.
我没用过modelservice
。
为道和服务class,我在XML和JAVA中有真名。在 IntelliJ IDEA 中,当我单击 XML 时,我可以转到 java class 我希望去的地方。
问题是,您在 XML 中为 totalCustomersDao
声明了 parent="abstractItemDao"
,另一方面您还没有实现 AbstractItemDao
class .
换句话说,您的 class 没有任何在您的 XML bean 定义中实际定义的 modelService 属性,它会导致 modelService
的 NotWritablePropertyException
或者 如果您完全不想使用 AbstractItemDao class 中的任何内容,您可以从 totalCustomersDao
声明中删除 parent="abstractItemDao"
.
<alias alias="totalCustomersDao" name="totalCustomersDao"/>
<bean id="totalCustomersDao"
class="de.hybris.training.core.dao.impl.TotalCustomersDaoImpl">
<property name="flexibleSearchService" ref="flexibleSearchService"/>
</bean>
或
在 TotalCustomersDaoImpl
中扩展 AbstractItemDao
class
public class TotalCustomersDaoImpl extends AbstractItemDao implements TotalCustomersDao
这是错误:
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;
}
错误显示 Bean property 'modelService' is not writable or has an invalid setter method.
我没用过modelservice
。
为道和服务class,我在XML和JAVA中有真名。在 IntelliJ IDEA 中,当我单击 XML 时,我可以转到 java class 我希望去的地方。
问题是,您在 XML 中为 totalCustomersDao
声明了 parent="abstractItemDao"
,另一方面您还没有实现 AbstractItemDao
class .
换句话说,您的 class 没有任何在您的 XML bean 定义中实际定义的 modelService 属性,它会导致 modelService
的 NotWritablePropertyException或者 如果您完全不想使用 AbstractItemDao class 中的任何内容,您可以从 totalCustomersDao
声明中删除 parent="abstractItemDao"
.
<alias alias="totalCustomersDao" name="totalCustomersDao"/>
<bean id="totalCustomersDao"
class="de.hybris.training.core.dao.impl.TotalCustomersDaoImpl">
<property name="flexibleSearchService" ref="flexibleSearchService"/>
</bean>
或
在 TotalCustomersDaoImpl
AbstractItemDao
class
public class TotalCustomersDaoImpl extends AbstractItemDao implements TotalCustomersDao