嗨,我正在尝试在Spring Boot应用程序启动时加载一些数据库值。我有自动接线的服务,在使用中我已经自动接线了。下面是错误。
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ validationExpressionService”的bean时出错:通过字段“ validationExpressionDao”表示的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'IValidationExpressionDao'的bean时出错:调用init方法失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:com.ril.nfg.dao.bean.ValidationExpression类
我添加了@EnitityScan @EnableJPARepository 仅供参考,对于String中的主键,希望没问题。
实体
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* The Class ValidationExpression.
*/
package com.ril.nfg.dao.bean;
@Entity
@Table(name = "VALIDATION_EXPRESSION")
public class ValidationExpression implements Serializable {
private static final long serialVersionUID = 9096950800262493651L;
private String validationId;
private String expression;
private String createdBy;
private Date createdOn;
private String description;
private String responseCode;
@Id
@Column(name = "VALIDATION_ID", nullable = false, length = 100)
public String getValidationId() {
return validationId;
}
public void setValidationId(String validationId) {
this.validationId = validationId;
}
@Column(name = "EXPRESSION", nullable = false, length = 200)
public String getExpression() {
return expression;
}
public void setExpression(String expression) {
this.expression = expression;
}
//remaining getters and setters
}
存储库
package com.ril.nfg.dao.repos;
import com.ril.nfg.dao.bean.ValidationExpression;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* The Interface IValidationExpressionDao.
*/
@Repository
public interface IValidationExpressionDao extends JpaRepository<ValidationExpression, String> {
}
服务
import java.util.List;
@Service
public class ValidationExpressionService {
@Autowired
IValidationExpressionDao validationExpressionDao;
public List<ValidationExpression> getAll() {
return validationExpressionDao.findAll();
}
}
具有@Autwired服务的类
public class CacheModuleParam implements ApplicationContextAware{
private static List<ValidationExpression> validationExpressionList = null;
@Autowired
ValidationExpressionService validationExpressionService;
@Override
public void setApplicationContext(final ApplicationContext appContext) throws BeansException {
validationExpressionList = validationExpressionService.getAll();
}
}
应用程序类
@ComponentScan(basePackages = {"com.ril.nfg"})
@EnableWebMvc
@EnableAutoConfiguration
@SpringBootApplication//(exclude={DataSourceAutoConfiguration.class})
@EnableJpaRepositories(basePackages="com.ril.nfg.dao.repos",entityManagerFactoryRef="oracleEntityManagerFactory")
//@EntityScan(basePackages = "com.ril.nfg.dao.bean")
public class NFGApplication {
public static void main(String[] args) {
SpringApplication.run(NFGApplication.class, args);
}
}
Internet上的所有解决方案都聚焦于@EntityScan。请帮助我了解此代码有什么问题。预先感谢
答案 0 :(得分:0)
为什么需要所有这些配置?只需将我们的应用程序放在所有其他类之上的一棵包树中,就可以使用这样的类:
@SpringBootApplication
public class NFGApplication {
public static void main(String[] args) {
SpringApplication.run(NFGApplication.class, args);
}
}
包装:
com.ril.nfg <- here you put NFGApplication
以及com.ril.nfg子包中的所有其他类
然后一切都会正常!