beg*_*ner 5 java spring hibernate spring-boot embedded-tomcat-8
我想做一个Spring Boot服务,在其中我可以从SQL Server数据库中获取所有表值或具有适当ID地址的值,因此,我使用了:
这是我的存储库界面:
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;
import ge.sda.spring.HoliDay.Data.*;
@Repository
public interface DayRepository extends CrudRepository<DayEntity, Integer> {
}
Run Code Online (Sandbox Code Playgroud)
这是我的服务:
@Service
public class CalculateHoliDayService {
@Autowired
public DayRepository repository;
public DayEntity getDayByID(Integer Id) {
return repository.findOne(Id);
}
public List<DayEntity> getAllDay(){
List<DayEntity>docs=new ArrayList<DayEntity>();
repository.findAll().forEach(docs::add);
return docs;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ge.sda.spring.HoliDay.Data.DayEntity;
import ge.sda.spring.HoliDayService.CalculateHoliDayService ;
@RestController
@RequestMapping("/profile/rest")
public class DayController {
@Autowired
public CalculateHoliDayService DayService;
@RequestMapping(value="/all")
public List<DayEntity> getAllDocument() {
return DayService.getAllDay();
}
@RequestMapping(value="/{id}")
public DayEntity getDocument(@PathVariable Integer Id) {
return DayService.getHoliDayByID(Id);
}
}
Run Code Online (Sandbox Code Playgroud)
这是application.properties:
# Server server.port=9010 spring.datasource.url=jdbc:sqlserver://url; servername=server;databaseName=Days
spring.datasource.username=user spring.datasource.password=*****
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
# Logging logging.level.com.bytestree.restful=DEBUG
Run Code Online (Sandbox Code Playgroud)
应用类别:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的pom:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
</jvmArguments>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
但是当我启动spring boot应用程序并尝试以下URL时: http:// localhost:9010 / profile / rest / 2
我收到此错误:
2018-03-26 15:44:02.416错误612-[nio-9010-exec-6] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]的Servlet.service()路径[]引发异常[请求处理失败;嵌套异常为java.lang.IllegalArgumentException:无法为所有解析存储库元数据。
java.lang.IllegalArgumentException:无法解析所有存储库元数据。在org.springframework.data.rest.webmvc.config.ResourceMetadataHandlerMethodArgumentResolver.resolveArgument(ResourceMetadataHandlerMethodArgumentResolver.java:97)〜[spring-data-rest-webmvc-2.6.6.RELEASE.jar:na]在org.springframework.data。 rest.webmvc.config.RootResourceInformationHandlerMethodArgumentResolver.resolveArgument(RootResourceInformationHandlerMethodArgumentResolver.java:83)〜[spring-data-rest-webmvc-2.6.6.RELEASE.jar:na] at org.springframework.data.rest.webmvc.config.RootResourceInformation .resolveArgument(RootResourceInformationHandlerMethodArgumentResolver.java:40)〜[spring-data-rest-webmvc-2.6.6.RELEASE.jar:na]在org.springframework.web.method.support.HandlerMethodArgumentResolverComposite。
为了使该服务正常工作,我应该进行哪些更改?
| 归档时间: |
|
| 查看次数: |
1174 次 |
| 最近记录: |