我有一个Spring Boot服务器,它存储库存在问题。
这是我的 Application.java
@EntityScan(basePackages= {"palmaslab.mapas.repository","palmaslab.mapas.security.registration","palmaslab.mapas.persistence.model"})
@EnableJpaRepositories(basePackages= {"palmaslab.mapas.repository","palmaslab.mapas.security.registration","palmaslab.mapas.persistence.dao"}/*.PostoSaudeRepository.class*/)
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages={"palmaslab.mapas.controller","palmaslab.mapas.security.registration","palmaslab.mapas.persistence.service","palmaslab.mapas.persistence.dao","palmaslab.mapas.persistence.model"})
@Import({palmaslab.mapas.security.SecurityConfiguration.class})
@EnableWebMvc
@PropertySource({"application.properties","classpath:email.properties.sample"})
public class Application extends /*WebMvcConfigurerAdapter*/ RepositoryRestMvcConfiguration{
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/**", "classpath:/resources/**", "classpath:/resources/static/img/",
"classpath:/static/", "classpath:/public/" };
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setPackagesToScan("palmaslab.mapas.repository","palmaslab.mapas.controller");
return lef;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(false);
hibernateJpaVendorAdapter.setGenerateDdl(true); //Auto creating scheme when true
hibernateJpaVendorAdapter.setDatabase(Database.H2);//Database type
return hibernateJpaVendorAdapter;
}
}
我有几个存储库位于不同的包中:palmaslab.mapas.repository
,palmaslab.mapas.security.registration
,palmaslab.mapas.persistence.dao
并且所有这些存储库都正常工作,除了ParametrosRepository
,这是自动更改的bean定义DefaultListableBeanFactory
。
这是 ParametrosRepository.java
@Repository
public interface ParametrosRepository extends CrudRepository<Parametros,Long>{
public Parametros findById(long id);
public List<Parametros> findByIdproject(long id);
public List<Parametros> findByIdprojectOrderBySortAsc(long id);
public List<Parametros> findByIdprojectOrderByPointtypeAscSortAsc(long id);
public List<Parametros> findByIdprojectAndPointtypeOrderBySortAsc(long id,long pt);
public List<Parametros> findBySortAndPointtypeAndIdproject(long sort,long pointtype, long idproject);
}
其中 Parametros Entity :
@Entity(name = "parametros")
public class Parametros {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@ElementCollection(fetch=FetchType.EAGER)
List<String> rrespostas = new ArrayList<String>();
@Size(max=1000)
String pergunta;
String title;
String note;
int type;
int multi_minimum;
int multi_maximum;
long idproject;
String extra_conf;
long sort = 0;
boolean photo = false;
long pointtype = 0;
public long getSort() {
return sort;
}
public long getPointtype() {
return pointtype;
}
public void setPointtype(long pointtype) {
this.pointtype = pointtype;
}
public boolean isPhoto() {
return photo;
}
public void setPhoto(boolean photo) {
this.photo = photo;
}
public void setSort(long sort) {
this.sort = sort;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Parametros(){
multi_minimum = 0;
multi_maximum = 0;
}
public void setId(long id) {
this.id = id;
}
public String getExtra_conf() {
return extra_conf;
}
public void setExtra_conf(String extra_conf) {
this.extra_conf = extra_conf;
}
public int getMulti_minimum() {
return multi_minimum;
}
public void setMulti_minimum(int multi_minimum) {
this.multi_minimum = multi_minimum;
}
public int getMulti_maximum() {
return multi_maximum;
}
public void setMulti_maximum(int multi_maximum) {
this.multi_maximum = multi_maximum;
}
public void setIdproject(long idproject) {
this.idproject = idproject;
}
public long getIdproject() {
return idproject;
}
public void setId_project(long idproject) {
this.idproject = idproject;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public long getId() {
return id;
}
public void addResposta(String resposta)
{
rrespostas.add(resposta);
}
public void removeResposta(int i)
{
rrespostas.remove(i);
}
public List<String> getRrespostas() {
return rrespostas;
}
public void setRrespostas(List<String> rrespostas) {
this.rrespostas = rrespostas;
}
public String getPergunta() {
return pergunta;
}
public void setPergunta(String pergunta) {
this.pergunta = pergunta;
}
}
PalmapController 中的ParametrosRepository
为@Autowired
:
@Controller
public class PalMapController {
@Autowired
private ParametrosRepository parametrosRepo;
[...]
}
这是错误:
2017-05-08 14:03:05.523 INFO 19384 --- [ main] o.s.b.f.s.**DefaultListableBeanFactory : Overriding bean definition for bean 'parametrosRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean];** scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2017-05-08 14:03:08.736 INFO 19384 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$c89aadcd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-05-08 14:03:10.166 INFO 19384 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 9876
2017-05-08 14:03:10.796 INFO 19384 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-05-08 14:03:10.805 INFO 19384 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.56
2017-05-08 14:03:11.052 INFO 19384 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-05-08 14:03:11.053 INFO 19384 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationConte ....
[...]
2017-05-08 13:11:42.562 ERROR 1015 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.**BeanCreationException: Error creating bean with name 'palMapController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private palmaslab.mapas.repository.ParametrosRepository palmaslab.mapas.controller.PalMapController.parametrosRepo**; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [palmaslab.mapas.repository.ParametrosRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at palmaslab.mapas.config.Application.main(Application.java:81)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private palmaslab.mapas.repository.ParametrosRepository palmaslab.mapas.controller.PalMapController.parametrosRepo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [palmaslab.mapas.repository.ParametrosRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 16 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [palmaslab.mapas.repository.ParametrosRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1326)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1072)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)
... 18 common frames omitted
其余的存储库和实体正常运行。任何人都知道为什么DefaultListableBeanFactory
正在改变ParametrosRepository Bean
?