Java 在abcService类中获取错误(字段xyzRepository(扩展JPA存储库)需要一个找不到的xyzRepository bean
sipRepository.javaJava 在abcService类中获取错误(字段xyzRepository(扩展JPA存储库)需要一个找不到的xyzRepository bean,java,Java,sipRepository.java import sip.sipDemo.model.mysql.SipEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; @Co
import sip.sipDemo.model.mysql.SipEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
@Component
@Repository
public interface SipRepository extends JpaRepository<SipEntity,Integer>{
}
SipController.java
package sip.sipDemo.Controller;
import sip.sipDemo.Service.SipService;
import sip.sipDemo.model.mysql.SipEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Optional;
@Controller
public class SipController {
@Autowired
private SipService sipservice;
@ResponseBody
@GetMapping(value="/")
public String home()
{
return "Hello";
}
@ResponseBody
@GetMapping(value = "/getAllEntities")
public List<SipEntity> getAllEntities()
{
List<SipEntity> newList = sipservice.getAllEntities();
return newList;
}
}
错误消息如下所示
: APPLICATION FAILED TO START
***************************
Description:
Field sipRepository in sip.sipDemo.Service.SipService required a bean of type 'sip.sipDemo.repository.mysql.SipRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'sip.sipDemo.repository.mysql.SipRepository' in your configuration.
> Task :SipDemoApplication.main() FAILED
应用程序属性
spring.datasource.url= jdbc:mysql://localhost:3306/sys?autoReconnect=true&zeroDateTimeBehavior=convertToNull
spring.datasource.username=root
spring.datasource.password=******** (actual password)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.org.hibernate.envers.audit_table_suffix=_AUDIT_LOG
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
package sip.sipDemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableAutoConfiguration
@ComponentScan(basePackages = {"sip.sipDemo"})
@SpringBootApplication
public class SipDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SipDemoApplication.class, args);
}
}
: APPLICATION FAILED TO START
***************************
Description:
Field sipRepository in sip.sipDemo.Service.SipService required a bean of type 'sip.sipDemo.repository.mysql.SipRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'sip.sipDemo.repository.mysql.SipRepository' in your configuration.
> Task :SipDemoApplication.main() FAILED
spring.datasource.url= jdbc:mysql://localhost:3306/sys?autoReconnect=true&zeroDateTimeBehavior=convertToNull
spring.datasource.username=root
spring.datasource.password=******** (actual password)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.org.hibernate.envers.audit_table_suffix=_AUDIT_LOG
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
│ │ └── sipDemo
│ │ ├── Controller
│ │ │ └── SipController.java
│ │ ├── model
│ │ │ └── mysql
│ │ │ └── SipEntity.java
│ │ ├── repository
│ │ │ └── mysql
│ │ │ └── SipRepository.java
│ │ ├── Service
│ │ │ └── SipService.java
│ │ └── SipDemoApplication.java
│ └── resources
│ ├── application.properties
│ ├── static
│ └── templates