相关疑难解决方法(0)

Spring Boot - 在类路径资源中定义名为'dataSource'的bean时出错

我有Spring Boot Web应用程序.它以RESTful方法为中心.所有配置似乎都存在但由于某种原因MainController无法处理请求.它导致404错误.怎么解决?

@Controller
public class MainController {

    @Autowired
    ParserService parserService;

    @RequestMapping(value="/", method= RequestMethod.GET)
    public @ResponseBody String displayStartPage(){
        return "{hello}";
    }
}
Run Code Online (Sandbox Code Playgroud)

应用

@Configuration
@ComponentScan(basePackages = "")
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer{
        public static void main(final String[] args) {
            SpringApplication.run(Application.class, args);
        }

        @Override
        protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
}
Run Code Online (Sandbox Code Playgroud)

ParserController

@RestController
public class ParserController {

    @Autowired
    private ParserService parserService;

    @Autowired
    private RecordDao recordDao;

 private static final Logger LOG = Logger.getLogger(ParserController.class);

    @RequestMapping(value="/upload", method= RequestMethod.POST)
    public …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

55
推荐指数
8
解决办法
26万
查看次数

Spring Boot app:没有拿起application.properties?

我有一个我在这里的春季启动应用程序:https: //github.com/christophstrobl/spring-data-solr-showcase/tree/4b3bbf945b182855003d5ba63a60990972a9de72

它编译并正常工作: mvn spring-boot:run

但是,当我在Spring Tools Suite中单击"作为Spring Boot应用程序运行"时,出现无法找到的错误 ${solr.host},指出 application.properties文件中设置的内容.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.data.solr.showcase.product.ProductServiceImpl.setProductRepository(org.springframework.data.solr.showcase.product.ProductRepository); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'solr.host' in string value "${solr.host}"
Run Code Online (Sandbox Code Playgroud)

我的applications.properties文件如下所示:

# SPRING MVC
spring.view.suffix=.jsp
spring.view.prefix=/WEB-INF/views/

# SOLR
solr.host=http://192.168.56.11:8983/solr
Run Code Online (Sandbox Code Playgroud)

相关类看起来像这样(唯一使用$ solr.host变量的地方).此外,如果我直接解决SOLR服务器的IP(如在注释代码中),应用程序就可以正常启动.

* Copyright 2012 - 2014 …
Run Code Online (Sandbox Code Playgroud)

java spring solr spring-mvc maven

18
推荐指数
7
解决办法
6万
查看次数

Spring Boot jdbc数据源自动配置在独立的tomcat上失败

在尝试在独立的tomcat(7)实例上部署和启动Spring启动应用程序时,我们遇到了一个问题,即找不到自动配置的spring数据源bean并抛出相应的异常:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [javax.sql.DataSource] 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:1060)  at 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:920)   at 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:815)     at 
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)   ... 84 more
Run Code Online (Sandbox Code Playgroud)

简单的jdbc spring.datasource在application.properties中正确配置,并且应用程序本身与嵌入式tomcat实例完美地运行,作为独立的spring引导应用程序.

看起来好像无法正确读取和/或处理application.properties文件,或者在数据源自动配置完成之前触发了一些其他bean(例如REST控制器中的服务)的注入.

不使用嵌入式tomcat时是否需要任何额外配置?或者有没有人遇到过类似的问题?

简单的应用和配置:

@EnableAutoConfiguration
@Configuration
@ComponentScan("com.foo")
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

}
Run Code Online (Sandbox Code Playgroud)

application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driverClassName=com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)

数据源使用示例:

@Repository …
Run Code Online (Sandbox Code Playgroud)

java spring datasource jdbc spring-boot

10
推荐指数
3
解决办法
4万
查看次数

BeanCreationException:无法确定数据库类型为NONE的嵌入式数据库驱动程序类

我正在尝试运行我的程序,我总是得到这个例外:

Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:137)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 45 more
Run Code Online (Sandbox Code Playgroud)

我通过gradle导入所有依赖项:

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
baseName = 'flatify-backend-service'
version =  '0.1.0'
}

repositories …
Run Code Online (Sandbox Code Playgroud)

java mysql gradle spring-data-jpa

7
推荐指数
1
解决办法
2万
查看次数

运行Spring Boot应用程序时出现DataSource错误

我是Spring boot的新手.我得到了这个错误

Cannot determine embedded database driver class for database type NONE

每当试图运行我的spring-boot启动web应用程序(我试图测试执行器和hal浏览器).在过去八个小时左右的时间里,我在google/stackoverflow上尝试了几个建议.但似乎并不适合我.我仍然继续得到另一个错误.

首先尝试: 我遵循journaldev中提到的两种方法

如果我使用第一种方法,即用我的主应用程序类注释@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class }),我会收到此错误:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Run Code Online (Sandbox Code Playgroud)

如果我使用第二种方法,我仍然会得到另一个错误:

Binding to target [Bindable@7c551ad4 type = com.zaxxer.hikari.HikariDataSource, value = 'provided', annotations = array<Annotation>[[empty]]] failed:

    Property: driverclassname
    Value: com.mysql.jdbc.Driver
    Origin: "driverClassName" from property source "source"
    Reason: Unable to set value for …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot

6
推荐指数
2
解决办法
3万
查看次数

H2嵌入DB,弹出启动错误自动配置

我正在尝试使用带有弹簧靴的H2嵌入式DB.但是,它会引发以下错误.

2016-10-19 22:05:25.818  INFO 14104 --- [           main] com.example.SpringDemoApplication        : Starting SpringDemoApplication on BOM1-LPMP12AS7U with PID 14104 (D:\workspace\eclipse\SpringDemo\target\classes started by e3028311 in D:\workspace\eclipse\SpringDemo)
2016-10-19 22:05:25.822  INFO 14104 --- [           main] com.example.SpringDemoApplication        : No active profile set, falling back to default profiles: default
2016-10-19 22:05:25.904  INFO 14104 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@543e710e: startup date [Wed Oct 19 22:05:25 IST 2016]; root of context hierarchy
2016-10-19 22:05:27.609  INFO 14104 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ece75ca4] …
Run Code Online (Sandbox Code Playgroud)

java jar h2 maven spring-boot

5
推荐指数
2
解决办法
1万
查看次数

spring-boot,spring-boot-starter-data-jpa:数据库类型为NONE或找不到更改日志位置

我再次,现在有一个spring-boot-starter-data-jpa问题.我使用spring-boot来访问多个数据库.MongoDB是正确的,也是Cassandra,最后一个PostgreSQL和JPA有一些问题.我认为我的配置可能有误.你能帮我解决一下吗?我使用了spring-boot,spring-data-jpa引用和spring-boot-starter-data-jpa引用.什么都没有帮助.我发现一些线程在stakeoverflow,使用jdbc与hsql依赖,因为jpa将无法正常工作链接.我自己尝试了这个,但是我得到了一个没有合格的bean错误.

所以我退后一步,包括jpa和hsql,写一个PostgresConfig类没有任何帮助.如果我使用@EnableJpaRepositories Annotation,我会收到有线错误.请参阅Stacktrace Para 67.5.2错误...我没有使用这个liquibase thingy,idk为什么会出现错误...否则,如果我不使用DataSourceBuilder,我的application.properties将无法读取,我得到了数据库键入NONE错误.

一些来源:堆栈跟踪:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) …
Run Code Online (Sandbox Code Playgroud)

spring spring-data-jpa spring-boot

3
推荐指数
1
解决办法
8628
查看次数

Spring Boot:无法配置数据源:未指定“url”属性且无法配置嵌入式数据源

当我运行我的网络应用程序时抛出以下错误。

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
Run Code Online (Sandbox Code Playgroud)

抛出错误的描述如下,

Description:

Failed to configure a DataSource: 'url' attribute is …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×6

spring ×6

spring-boot ×6

maven ×2

spring-data-jpa ×2

datasource ×1

gradle ×1

h2 ×1

jar ×1

jdbc ×1

mysql ×1

solr ×1

spring-mvc ×1