springboot启动报错:Error starting ApplicationContext. To display the auto-configuration report re-run yo

今天想做个分布式的小demo,结果跑springboot的时候出错:

log4j:ERROR Could not find value for key log4j.appender.socket
log4j:ERROR Could not instantiate appender named "socket".

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.6.RELEASE)

2018-08-05 10:56:03,815  INFO [StartupInfoLogger.java:48] : Starting Application on DESKTOP-VQJVA3M with PID 15236 (E:\zookeepr2\cs_service\target\classes started by ASUS in E:\zookeepr2\cs_service)
2018-08-05 10:56:03,835  INFO [SpringApplication.java:593] : No active profile set, falling back to default profiles: default
2018-08-05 10:56:03,881  INFO [AbstractApplicationContext.java:583] : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2e3fc542: startup date [Sun Aug 05 10:56:03 CST 2018]; root of context hierarchy
2018-08-05 10:56:04,232  INFO [XmlBeanDefinitionReader.java:317] : Loading XML bean definitions from class path resource [dubbo/dubbo-provider.xml]
2018-08-05 10:56:04,363  INFO [?:?] : using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter
2018-08-05 10:56:04,412  WARN [ClassPathMapperScanner.java:166] : No MyBatis mapper was found in '[com.st.eleventh]' package. Please check your configuration.
2018-08-05 10:56:04,857  WARN [AbstractApplicationContext.java:551] : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
2018-08-05 10:56:04,865  INFO [AutoConfigurationReportLoggingInitializer.java:101] : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-08-05 10:56:04,870 ERROR [LoggingFailureAnalysisReporter.java:42] : 

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

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

2018-08-05 10:56:04,874  INFO [AbstractConfig.java:450] :  [DUBBO] Run shutdown hook now., dubbo version: 2.5.3, current host: 127.0.0.1
2018-08-05 10:56:04,875  INFO [AbstractRegistryFactory.java:63] :  [DUBBO] Close all registries [], dubbo version: 2.5.3, current host: 127.0.0.1

启动类Application:

package com.st.eleventh;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication

@ImportResource({  "classpath:dubbo/dubbo-provider.xml" })
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
		try {
			System.in.read();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

经过排查:是因为springboot启动时会自动注入数据源和配置jpa 

所以解决方法:

在@SpringBootApplication中排除其注入 
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

package com.st.eleventh;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
@ImportResource({  "classpath:dubbo/dubbo-provider.xml" })
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
		try {
			System.in.read();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

再次run项目,springboot能成功运行。

注:由于我只是测试下demo,没有用到数据库数据才

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class});

项目用到数据库,只要你数据库连接,mapper映射配好,  直接@SpringBootApplication,运行项目就不会报这个错误。

 

我的座右铭:不会,我可以学;落后,我可以追赶;跌倒,我可以站起来;我一定行。

springboot启动报错:Error starting ApplicationContext. To display the auto-configuration report re-run yo_第1张图片

你可能感兴趣的:(bug错误相册,分布式)