Error creating bean with name 'resourceHandlerMapping' - java

I have an application with spring that use a JpaConfiguration class to deal with my database, and a WebAppMvcConfigurer class to deal with the front via json message. Both have an #Configuration and are in the same package. I have an App class in a root package with #Configuration and #ComponentScan with my main method.
When I launch App class I get this error :
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:89)
at com.bnpp.creditauto.App.main(App.java:22)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651)
... 14 more
Caused by: java.lang.IllegalStateException: No ServletContext set
at org.springframework.util.Assert.state(Assert.java:73)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:533)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 15 more
What "works" so far is delete one of the two #Configuration in either JpaConfiguration or WebAppMvcConfigurer. If i delete the #Configuration WebApp one i can interact with my database no problem, but cant access anything from my angular application.
If I delete the #Configuration in JpaConf the front part of the application works and I can access the json my Java application sends with my angular application no problem, but cant do anything with my database.
Somewhere I read to change #Configuation to #WebAppConfiguration in WebAppMvcConfigurer, it does the same as removing the #Configuration, JpaConfiguration works fine and front part doesnt work.
I checked dependencies and tried the last version without success.
I tried to change in App : #ComponentScan(basePackages = { "org.example.springproject" }, excludeFilters = { #Filter(type = FilterType.ANNOTATION, value = Configuration.class) })
without success too, it is the same as deleting both #Configuration in Jpa and webapp
My app class :
package com.bnpp.creditauto;
#Configuration
#ComponentScan//("com.bnpp.creditauto")
public class App {
public static void main(String[] args) {
...
}
JpaConfiguration class :
package com.bnpp.creditauto.config;
#Configuration
#EnableTransactionManagement
#PropertySource("classpath:application.properties")
public class JpaConfiguration {
...
}
WebAppMvcConfigurer class :
package com.bnpp.creditauto.config;
#Configuration
#EnableWebMvc
public class WebAppMvcConfigurer implements WebMvcConfigurer {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
}
#Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}

So I found the answer, you can't launch the main method with a spring context when you have a #Configuration in a WebMvcConfigurer class and #Configuration in a class handling your Jpa configuration.
If you remove either config you can use your main method but the class without #Configuration will stop working. To create a method that initializes or tests and call it with HTTP request in a browser or your application dealing with the front part and it will work fine.

Thought of adding another scenario if someone cant still find the issue. So with the annotation "#SpringBootApplication" spring takes care most of the sub annotations like "#ComponentScan". let's say you have a test config class and you give your own component scan packages, then the default application level context loading wont happen. so in this case you only want to stick with other configuration like injecting your own property files with datasources (mem dbs)

Related

Why does InboundChannelAdapter not work in SpringBootTest

In a spring-boot project i am using the following code:
import org.springframework.integration.core.MessageSource;
#Configuration
public class Config
{
#Bean
#InboundChannelAdapter(channel = "channel1", autoStartup = "false",
poller = #Poller("poller"))
public MessageSource messages() throws Exception
{
...
to poll a mailaccount for incoming messages. This works fine so far.
The problem arises when i try to call some tests in a class that is annotated with #SpringBootTest. Then the initialisation of my testclass fails:
2023-01-12T16:43:03.846+01:00 ERROR 3625 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener#63648ee9] to prepare test instance [MyClass#b849fa6]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:131) ~[spring-test-6.0.0-M5.jar:6.0.0-M5]
<... stacktrace ...>
Caused by: java.lang.IllegalArgumentException: The 'interface org.springframework.integration.annotation.InboundChannelAdapter' on #Bean method level is allowed only for: org.springframework.integration.core.MessageSource, or java.util.function.Supplier, or kotlin.jvm.functions.Function0 beans
<... more stacktrace...>
I can't see the problem here, since the annotation is used together with MessageSource. Can someone help me on this one, please?
update in reply to the comment from Vitaly Chura:
in fact, that does not tell me much, unfortunately, but i will give it a try:
Caused by: java.lang.IllegalArgumentException: The 'interface org.springframework.integration.annotation.InboundChannelAdapter' on #Bean method level is allowed only for: org.springframework.integration.core.MessageSource, or java.util.function.Supplier, or kotlin.jvm.functions.Function0 beans
at org.springframework.util.Assert.isTrue(Assert.java:139) ~[spring-core-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.integration.config.annotation.InboundChannelAdapterAnnotationPostProcessor.createMessageSource(InboundChannelAdapterAnnotationPostProcessor.java:100) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.integration.config.annotation.InboundChannelAdapterAnnotationPostProcessor.postProcess(InboundChannelAdapterAnnotationPostProcessor.java:72) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.postProcessMethodAndRegisterEndpointIfAny(MessagingAnnotationPostProcessor.java:231) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.lambda$processAnnotationTypeOnMethod$4(MessagingAnnotationPostProcessor.java:220) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.afterSingletonsInstantiated(MessagingAnnotationPostProcessor.java:135) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:941) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:926) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:592) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:430) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:132) ~[spring-boot-test-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) ~[spring-test-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:123) ~[spring-test-6.0.0-M5.jar:6.0.0-M5]
... 72 common frames omitted
I know this does not explain the IllegalArgumentException, but for reasons of pragmatism i circumvented this problem by implementing a dummy configuration class inside the test-folder of the maven-project that provides the same beans as the original but does not use the #InboundChannelAdapter, as suggested by Matheus Santz in how-to-exclude-java-configuration-class-from-test-context. So for the tests this new dummy class is used.
Thanx to Vitaly Chura and all others reading.

Spring Error creating bean with name 'covidController' defined in file

First of all, you may think/vote this question as a duplicate. Let me tell you, I have tried almost every possible solution on SO and not on SO.
I am using the Spring framework for a project and the project is based on a layered architecture. I have tried to fix an exception that is thrown when I start the Spring. I am trying to solve this for the last few days and I was not able to solve it. (I am new to spring)
I have three layers:
domain
persistence
rest
When I start the application, it throws me an error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'covidController' defined in file [......./layered-architecture-spring/rest/target/classes/com/comp/rest/CovidController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'covidRepository' defined in com.comp.persistence.CovidRepository defined in #EnableJpaRepositories declared on RestApp: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.comp.persistence.CovidRepository.fetchAllData()! No property fetchAllData found for type Covid!
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.comp.persistence.CovidRepository.fetchAllData()! No property fetchAllData found for type Covid!
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property fetchAllData found for type Covid!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.3.0.RELEASE.jar:2.3.0.RELEASE]
My whole project on GitHub: https://github.com/Phoenix404/ssa-layered-assignment
#RestController
public class CovidController {
private final CovidRepository covidRepository;
public CovidController(CovidRepository cr) {
covidRepository = cr;
}
#GetMapping("/cdata")
public List<Covid> getList() {
return this.covidRepository.findByLocation("italy");
}
}
#Repository
public interface CovidRepository extends JpaRepository<Covid, Integer> {
List<Covid> fetchAllData();
List<Covid> findByDate(Date date);
List<Covid> findByLocation(String location);
}
CovidController is my Rest app controller inside the rest module. The CovidRepository is in the persistence module.
I am using the following annotations for scanning the classes as suggested on other SO but I am still getting the error:
#SpringBootApplication
#EnableJpaRepositories("com.comp.**persistence**")
#EntityScan(basePackages = {"com.comp.**"})
#ComponentScan(basePackages = {"com.comp.**"})
#SpringBootApplication
#EnableJpaRepositories("com.comp.persistenc*")
#EntityScan(basePackages = {"com.comp"})
#ComponentScan(basePackages = {"com.comp"})
#SpringBootApplication
#EnableJpaRepositories("com.comp.*")
#EntityScan(basePackages = {"com.comp.*"})
#ComponentScan(basePackages = {"com.comp.*"})
What am I doing wrong?
Thanks to #aniket-sahrawat, for solving the question.
The problem is solved, when I removed the methods from my covidRepository.

#ContextConfiguration not bringing in only the config classes specified

I noticed that with #EnableWebMvc I'm getting the following error when running my tests: A ServletContext is required to configure default servlet handling. This issue is temporarily resolved by commenting out #EnableWebMvc then my tests all pass, however I want this in my web app.
I read in this post that I could put the #EnableWebMvc in another config class that isn't included in the tests(?). So I've tried this:
AppConfig.java
#Configuration
#ComponentScan(basePackages = "biz.martyn.budget")
#PropertySource("classpath:prod.properties")
#EnableTransactionManagement
public class AppConfig {
#Autowired
private Environment env;
#Bean(name = "dataSource", destroyMethod = "shutdown")
#Profile("prod")
public DataSource dataSourceForProd() {...
WebMvcConfig.java
#Configuration
#EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
#Bean
public ViewResolver viewResolver() {...
Then in my tests I'm attempting:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(classes = AppConfig.class)
#Transactional
public class FundRepositoryTest {...
However, I'm still seeing the same error in my tests. I know it's the #EnableWebMvc as they all pass when I remove this. Have I misunderstood something with how #ContextConfiguration annotation works? By the way, I'm using Spring version 4.2.2.RELEASE for all my spring-* dependencies if that helps.
Below is also the error I'm seeing in my test run:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
I'm still not sure why the #ContextConfiguration annotation isn't only accepting the class(es) I provide but I have found that #WebAppConfiguration added to each test class provides the context required:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(classes = AppConfig.class)
#Transactional
#WebAppConfiguration // <-- added this
public class FundRepositoryTest {...
It's an additional annotation I need to add though but my tests run now.

springSecurityFilterChain - ObjectPostProcessor is a required bean Exception

I am building a Spring Boot application with Spring Security (spring-boot-starter-web and spring-boot-starter-security). I receive the following error from my application during boot:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used #EnableWebSecurity and #Configuration
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:625) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:455) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
...
My application class consists of the following:
#SpringBootApplication
public class CustomPropertiesApplication {
public static void main(String[] args) {
SpringApplication.run(CustomPropertiesApplication.class, args);
}
}
The bean in this next class appears to be the issue. If it's excluded then the application will boot without error.
#Configuration
#EnableWebSecurity
public class MyConfig extends WebSecurityConfigurerAdapter {
#Bean
public CustomPropertyPlaceholderConfigurer propertyConfigurer(ApplicationContext context) {
return new CustomPropertyPlaceholderConfigurer();
}
}
Right now this CustomPropertyPlaceholderConfigurer class does nothing, I have some legacy classes that are similar, but in trying to troubleshoot this issue I eliminated everything else from my test application.
public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
}
I'm at a loss of what to try next. I've looked for details in Spring Security and Spring Boot about building a custom property placeholder configurer, but I didn't find anything useful.
Versions: Spring Boot - 2.1.0.RELEASE | Spring Security - 5.1.1.RELEASE | JDK 1.8
Also, I realize this app doesn't really do anything, there is a much larger application that has much more complicated logic, and this sample app here is just to replicate my issue to make it small for stackoverflow.
I see now that the answer was right in my output logs and I just failed to see it.
o.s.c.a.ConfigurationClassEnhancer : #Bean method MyConfig.propertyConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as #Autowired, #Resource and #PostConstruct within the method's declaring #Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see #Bean javadoc for complete details.
Adding static to my bean fixed the issue.

Error creating bean with name 'dataSource' defined in class path resource + Springboot

I'm creating a Springboot application but will be using a external MongoDB over REST. My application properties file is very simple:
application.properties
# Server
server.port=8081
My global application file is also very simple. I make a connection to my externally hosted database with a Parse initialization method:
#SpringBootApplication
#ComponentScan(basePackages = {"com.test", "it.ozimov.springboot"})
public class TmtApplication {
public static void main(String[] args) {
SpringApplication.run(TmtApplication.class, args);
// Database connection
Parse.initialize("applicationId","restAPIKey", "https://parseapi.back4app.com");
}
}
Why am I getting the following exception?
Exceptions:
Caused by: 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).
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 34 more
Caused by: 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).
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 47 more
Caused by: 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).
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:246)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:183)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:42)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat.dataSource(DataSourceConfiguration.java:56)
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:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 48 more
What don't I understand about Springboot? Is it looking for some kind of database initialization because it's running on Hibernate/Tomcat?
Exclude Datasource if you don't use database.
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
you see this link
For some reason, having #SpringBootApplication and then #EnableAutoConfiguration didn't work for me.
What worked for me is:
#SpringBootApplication (exclude = {DataSourceAutoConfiguration.class})
#DependsOn("appConfig")
public class SerializationManager {
}
Using #SpringBootApplication is the same as having #Configuration #EnableAutoConfiguration and #ComponentScan separately.

Categories

Resources