GVKun编程网logo

带有Spring-boot CLI的RepositoryRestResource(springboot包含)

14

对于带有Spring-bootCLI的RepositoryRestResource感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解springboot包含,并且为您提供关于AResource

对于带有Spring-boot CLI的RepositoryRestResource感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解springboot包含,并且为您提供关于A ResourcePool could not acquire a resource from its primary factory or source.、c# – 关于resources.ApplyResources的System.Resources.MissingManifestResourceException、CityESServiceImpl required a bean of type ''org.spring.springboot.repository.CityRepository'' that could not be found.、Java 无法在 IntelliJ 中导入 Spring RepositoryRestResource的宝贵知识。

本文目录一览:

带有Spring-boot CLI的RepositoryRestResource(springboot包含)

带有Spring-boot CLI的RepositoryRestResource(springboot包含)

我正在尝试基于具有spring-boot和spring-data-
rest的JPA存储库实现一个简单的REST服务。(请参阅本教程)如果将下面的代码与gradle一起使用,则效果很好:

package ch.bfh.swos.bookappimport org.springframework.boot.SpringApplicationimport org.springframework.boot.autoconfigure.EnableAutoConfigurationimport org.springframework.context.annotation.*import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfigurationimport org.springframework.data.jpa.repository.config.EnableJpaRepositoriesimport org.springframework.context.annotation.Importimport org.springframework.data.rest.core.annotation.RepositoryRestResourceimport org.springframework.data.repository.CrudRepositoryimport javax.persistence.*@Configuration@ComponentScan@EnableAutoConfiguration@EnableJpaRepositories@Import(RepositoryRestMvcConfiguration.class)class Application {    static void main(String[] args) {        SpringApplication.run Application, args    }}@RepositoryRestResource(path = "authors")interface AuthorRepository extends CrudRepository<Author, Long> {}@Entityclass Author {    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Long id    private String firstname    private String lastname}

为了使事情更简单,我尝试了使用spring boot CLI(“ spring run”命令)使用相同的代码。

package ch.bfh.swos.bookapp@Grab("spring-boot-starter-data-jpa")@Grab("spring-boot-starter-data-rest")@Grab("h2")import org.springframework.boot.autoconfigure.EnableAutoConfigurationimport org.springframework.context.annotation.ComponentScanimport org.springframework.context.annotation.Configurationimport org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfigurationimport org.springframework.data.jpa.repository.config.EnableJpaRepositoriesimport org.springframework.context.annotation.Importimport org.springframework.data.rest.core.annotation.RepositoryRestResourceimport org.springframework.data.repository.CrudRepositoryimport javax.persistence.*@Configuration@ComponentScan@EnableAutoConfiguration@EnableJpaRepositories@Import(RepositoryRestMvcConfiguration.class)@RepositoryRestResource(path = "authors")interface AuthorRepository extends CrudRepository<Author, Long> {}@Entityclass Author {    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Long id    private String firstname    private String lastname}

不幸的是,这似乎不起作用。@RepositoryRestResource似乎不会像@RestController这样被自动识别。保留@Configuration部分,服务器将启动,但不会像使用gradle那样创建REST存储库。

有人知道是否可以使用spring-boot CLI创建RepositoryRestResource,以及正确的代码应如何显示?

答案1

小编典典

您需要一个类定义来挂起它@Import(其他在类上而不是在接口上的注释是多余的)。

更新: 并且
(更重要的是)除非它们实际上在文件中,否则Hibernate无法找到带注释的类(它注释性地分析字节码而不是类定义)。因此,您可以通过加扰并以这种方式运行它来使您的应用工作:

$ spring jar app.jar app.groovy$ java -jar app.jar

这是该应用程序的较短版本,其工作方式与删除所有多余内容的方式相同:

package bookapp@Grab("spring-boot-starter-data-jpa")@Grab("spring-boot-starter-data-rest")@Grab("h2")import org.springframework.data.rest.core.annotation.RepositoryRestResourceimport org.springframework.data.repository.CrudRepositoryimport javax.persistence.*@Configurationclass App {}@RepositoryRestResource(path = "authors")interface AuthorRepository extends CrudRepository<Author, Long> {}@Entityclass Author {  @Id  @GeneratedValue(strategy = GenerationType.AUTO)  private Long id  String firstname  String lastname}

A ResourcePool could not acquire a resource from its primary factory or source.

A ResourcePool could not acquire a resource from its primary factory or source.

严重: Servlet.service () for servlet [dispatcherServlet] in context with path [/heima_ssm_web1] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in com/itheima/ssm/dao/IProductDao.java (best guess)
### The error may involve com.itheima.ssm.dao.IProductDao.findAll
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!] with root cause
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.

 

问题解决

1. 检查数据库配置;

2. 如果你和我一样也是虚拟机中的数据库,检查虚拟机中数据库是否还能链接

c# – 关于resources.ApplyResources的System.Resources.MissingManifestResourceException

c# – 关于resources.ApplyResources的System.Resources.MissingManifestResourceException

这是我正在努力的代码:

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EditorPane));
this.editorControl = new EditorControl();
resources.ApplyResources(this.editorControl,"editorControl",CultureInfo.CurrentUICulture);

当代码执行时,它抛出一个’System.Resources.MissingManifestResourceException’,所有错误消息都只是吼叫.

An exception of type ‘System.Resources.MissingManifestResourceException’ occurred in mscorlib.dll but was not handled in user code

Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure “Editor.EditorPane.resources” was correctly embedded or linked into assembly “Editor” at compile time,or that all the satellite assemblies required are loadable and fully signed.

解决方法

对我来说,问题不是任何内部类定义.相反,问题源是在项目文件中,这花了我很长时间才发现.

这是我在项目文件中找到的:

<EmbeddedResource Include="Main.resx" />

这就是它必须:

<EmbeddedResource Include="Main.resx">
  <DependentUpon>Main.pas</DependentUpon>
</EmbeddedResource>

如果没有列出这种依赖关系(我必须强调,我没有自己删除它 – 它是在某个阶段由MS Visual Studio完成的),必要的资源文件没有在编译例程中正确包含.

我希望这会有所帮助(并让其他人头疼)!

CityESServiceImpl required a bean of type ''org.spring.springboot.repository.CityRepository'' that could not be found.

CityESServiceImpl required a bean of type ''org.spring.springboot.repository.CityRepository'' that could not be found.

 Bean ''validator'' of type [class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-08 13:43:40.636  INFO 9300 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2019-04-08 13:43:40.651  INFO 9300 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2019-04-08 13:43:40.652  INFO 9300 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.11
2019-04-08 13:43:40.765  INFO 9300 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-04-08 13:43:40.765  INFO 9300 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1407 ms
2019-04-08 13:43:40.883  INFO 9300 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: ''dispatcherServlet'' to [/]
2019-04-08 13:43:40.887  INFO 9300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ''characterEncodingFilter'' to: [/*]
2019-04-08 13:43:40.887  INFO 9300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ''hiddenHttpMethodFilter'' to: [/*]
2019-04-08 13:43:40.887  INFO 9300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ''httpPutFormContentFilter'' to: [/*]
2019-04-08 13:43:40.887  INFO 9300 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ''requestContextFilter'' to: [/*]
2019-04-08 13:43:40.937  WARN 9300 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''cityRestController'': Unsatisfied dependency expressed through field ''cityService''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''cityESServiceImpl'': Unsatisfied dependency expressed through field ''cityRepository''; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''org.spring.springboot.repository.CityRepository'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2019-04-08 13:43:40.943  INFO 9300 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with ''debug'' enabled.
2019-04-08 13:43:41.017 ERROR 9300 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field cityRepository in org.spring.springboot.service.impl.CityESServiceImpl required a bean of type ''org.spring.springboot.repository.CityRepository'' that could not be found.


Action:

Consider defining a bean of type ''org.spring.springboot.repository.CityRepository'' in your configuration.

Java 无法在 IntelliJ 中导入 Spring RepositoryRestResource

Java 无法在 IntelliJ 中导入 Spring RepositoryRestResource

如何解决Java 无法在 IntelliJ 中导入 Spring RepositoryRestResource?

我正在使用 IntelliJ。我收到以下错误,

@RepositoryRestResource
public interface CarRepository extends CrudRepository <Car,Long> {

错误:无法解析符号“RepositoryRestResource”

所以我按照 Spring Initializer 中的说明在下面添加了几行

建议的解决方案:

Unable to import Spring RepositoryRestResource

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

在 POM 中添加这一行会产生与此相同的错误:

错误:未找到依赖项 ''org.springframework.boot:spring-boot-starter-data-rest:2.5.3''

我该如何解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

关于带有Spring-boot CLI的RepositoryRestResourcespringboot包含的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于A ResourcePool could not acquire a resource from its primary factory or source.、c# – 关于resources.ApplyResources的System.Resources.MissingManifestResourceException、CityESServiceImpl required a bean of type ''org.spring.springboot.repository.CityRepository'' that could not be found.、Java 无法在 IntelliJ 中导入 Spring RepositoryRestResource等相关内容,可以在本站寻找。

本文标签: