Spring application properties file not taking in tomcat in windows envt - java

While deploying Spring application in Apache tomcat version 7 getting below error in Windows,But in the same application working in linux environment.
The properties files are in webapps/{contextname}/WEB-INF/classes in both environment.
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'entityManagerFactory' defined in
com.org.app.web.config.DatabaseConfig: Unsatisfied dependency
expressed through constructor argument with index 0 of type
[java.util.Properties]: No qualifying bean of type
[java.util.Properties] found for dependency: expected at least 1 bean
which qualifies as autowire candidate for this dependency. Dependency
annotations:
{#org.springframework.beans.factory.annotation.Qualifier(value=hibernateProperties)};
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [java.util.Properties] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for
this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Qualifier(value=hibernateProperties)}
Please help me to solve this
The code snippet attached below
#Configuration
#PropertySource("classpath:config.properties")
public class WebConfig {
}
#Bean(name = "entityManagerFactory")
#Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
#Qualifier("hibernateProperties") final Properties props) {
}
#DevelopmentProfile
#FullProfile
#Bean(name = "hibernateProperties")
public Properties additionalProperties() {
}

Related

Spring Boot 2 datasource by configuration does not work

I have an application.yml(!) for the configuration containing the following:
spring:
datasource:
url: "jdbc:h2:file:./camunda-h2-database"
driverClassName: "org.h2.Driver"
username: "sa"
password: ""
Which gives me the errormessage:
2021-03-11T17:02:48,600 WARN [main] o.s.c.s.AbstractApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.camunda.bpm.spring.boot.starter.CamundaBpmAutoConfiguration$ProcessEngineConfigurationImplDependingConfiguration': Unsatisfied dependency expressed through field 'processEngineConfigurationImpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngineConfigurationImpl' defined in class path resource [org/camunda/bpm/spring/boot/starter/CamundaBpmConfiguration.class]: Unsatisfied dependency expressed through method 'processEngineConfigurationImpl' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'camundaDatasourceConfiguration': Unsatisfied dependency expressed through field 'dataSource'; nested exception is 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: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
Doing it this way works:
public DriverManagerDataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.h2.Driver");
dataSource.setUrl("jdbc:h2:file:./camunda-h2-database");
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}
#Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
Ideas? :-)
Rename driverClassName to driver-class-name since Kebab case is preferred over Camel case in Spring Boot Auto Configuration properties.
If that doesn't help then make sure that you didn't turn off DataSourceAutoConfiguration feature. It usually may look like
#SpringBootApplication(exclude = [DataSourceAutoConfiguration::class])
public class BootApplication { ... }

Executable JAR with testng giving "expected at least 1 bean which qualifies as autowire candidate for this dependency."

Through maven command everything is fine and tests are running good.
I am creating an executable jar which will except same arguments and run the testng tests.
I am using assembly plugin to create the executable jar with my main method class.
When running through jar
java -jar <jar name>.jar
Getting following error.
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'apiClientFacade' defined in
com.test.framework.TestContext: Unsatisfied dependency
expressed through constructor argument with index 0 of type
[com.test.framework.configuration.TestConfiguration]: :
No qualifying bean of type
[com.test.framework.configuration.TestConfiguration]
found for dependency: expected at least 1 bean which qualifies as
autowire candidate for this dependency. Dependency annotations: {};
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
[com.test.framework.configuration.TestConfiguration]
found for dependency: expected at least 1 bean which qualifies as
autowire candidate for this dependency. Dependency annotations:
Related JAVA files
TestContext.java
#Configuration
#Import({EmbeddedContext.class, FullDataContext.class})
public class TestContext {
#Bean
#Autowired
#Primary
public ApiClientFacade apiClientFacade(TestConfiguration configuration,
#Qualifier("apiClient") ApiClient apiClient) {
return new ApiClientFacadeImpl(configuration, apiClient);
}
}
TestConfiguration.java
#Component
public class TestConfiguration { }
ApiClientFacadeImpl.java
#Component
public class ApiClientFacadeImpl implements ApiClientFacade {
}
ApiClientFacade.java
public interface ApiClientFacade {}

Injection of autowired dependencies failed inside a jar file

I have put a jar file under lib folder of my war file. Inside the jar I have some classes with #Autowired fileds. Inside the jar , in the applicationContext xml I have given
<context:component-scan base-package="com.main.java.mypath" />
Code:
package com.main.java.mypath.client;
#Component
public class ServiceProvider {
#Autowired
private StoreField storeField;
package com.main.java.mypath.data;
public interface StoreField {
}
Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.main.java.mypath.data.StoreField com.main.java.mypath.client.ServiceProvider.storeField; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.main.java.mypath.data.StoreField] 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)}
It is not possible to inject the dependency as long as you don't have the implementation for your StoreField interface. Make sure that it is implemented as a class and properly initialized in spring context via xml or annotation.

Use Bean from an another module

I am creating a Batch application to put some data from a web-service on the database.
To do this I need to convert DTO's received by the web-service on utilizable classes. This is possible using some mapper defined in an other module.
When I tried to #Autowired the mapper I have an Exception and I don't find how to pass out.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.execution.batch.processor.UtilisateurProcessor com.execution.batch.jobConfiguration.JobConfigurationAbstract.utilisateurProcessor; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utilisateurProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] 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)}
**Caused by**: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.execution.batch.processor.UtilisateurProcessor com.execution.batch.jobConfiguration.JobConfigurationAbstract.utilisateurProcessor; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utilisateurProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] 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)}
**Caused by**: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utilisateurProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] 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)}
**Caused by**: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.execution.server.common.mapper.UtilisateurMapper com.execution.batch.processor.UtilisateurProcessor.utilisateurMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] 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)}
**Caused by**: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.execution.server.common.mapper.UtilisateurMapper] 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)}
The mappers are working fine in their module. I can #Autowierdd them and use it without problems. And the my batch is working fine if I don't #Autowierd the mapper.
Someone have an idea?
Thanks!
EDIT
My configuration is on my job configuration class :
#Configuration
#EnableBatchProcessing
#ComponentScan(basePackages = {"com.execution.batch"})
I tried to put : #ComponentScan(basePackages = {"com.execution.batch", "com.execution.serve"})
But if I do that I have errors reported to the injection of the job's bean :
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.configuration.annotation.StepBuilderFactory com.execution.batch.jobConfiguration.JobConfigurationAbstract.stepBuilderFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.configuration.annotation.StepBuilderFactory com.execution.batch.jobConfiguration.JobConfigurationAbstract.stepBuilderFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepository' defined in com.execution.batch.jobConfiguration.JobConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager]: : No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.support.transaction.ResourcelessTransactionManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Like I said, separately the to modules work fine.
when I scan the server and the batch module the scan of the batch don't work.
When I scan just the batch module, the server module don't work because isn't scan I think.
Since your configurations work independently, there is a good change that you have conflicting names in both packages. Which could result that configurations or beans are overwritten.
E.g.
package com.x;
#Configuration
public class AConfiguration {
}
package com.y;
#Configuration
public class AConfiguration {
}
As the beanname in the springcontext, only the class name is used without the package. So, if you scan both packages, only an Configuration-Class will actually be processed. The same is also valid for classes annotated with #Component.
It is important to understand, that #Component and #Configuration classes are also instantiated as beans, with the simple classname as beanname.
Also with #Bean annoted methods are a potential source of errors. If you have the same methodname in two different Configuration-Beans, only one will be instantiated.
Moreover, if you use as #Bean methodname the same name as a #Configuration class name has, then again, one is overwritten by the other.
I guess that you have forgotten to set the "scanner" with the appropriate package of the class that you want.
Your bean is utilisateurProcessor, fqn is com.execution.batch.processor.UtilisateurProcessor. Is it configured as a #Component or in your XML?
Please paste the spring' config, to see if you have added com.execution.server.common.mapper to Spring's scanner.

Having an issue with launching Spring Cloud Hystrix Dashboard Example

Trying to launch a Hystrix dashboard and receiving an error upon launch. Following the example provided via github as the base. Have not made any changes to the code really. Just trying to launch.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Configuration
#ComponentScan
#EnableAutoConfiguration
#EnableHystrixDashboard
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
#Controller
class HystrixDashboardController {
#RequestMapping("/")
public String home() {
return "forward:/hystrix/index.html";
}
}
Below is the error being reported:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restTemplate' defined in class path resource [org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.cloud.netflix.ribbon.RibbonInterceptor]: : Error creating bean with name 'ribbonInterceptor' defined in class path resource [org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.cloud.client.loadbalancer.LoadBalancerClient]: : Error creating bean with name 'loadBalancerClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.cloud.netflix.ribbon.SpringClientFactory org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.clientFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.cloud.netflix.ribbon.SpringClientFactory] 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)}; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadBalancerClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.cloud.netflix.ribbon.SpringClientFactory org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.clientFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.cloud.netflix.ribbon.SpringClientFactory] 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)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ribbonInterceptor' defined in class path resource [org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.cloud.client.loadbalancer.LoadBalancerClient]: : Error creating bean with name 'loadBalancerClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.cloud.netflix.ribbon.SpringClientFactory org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.clientFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.cloud.netflix.ribbon.SpringClientFactory] 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)}; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadBalancerClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.cloud.netflix.ribbon.SpringClientFactory org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.clientFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.cloud.netflix.ribbon.SpringClientFactory] 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)}
I have tried both spring-cloud-starters 1.0.0.BUILD-SNAPSHOT & 1.0.0.M1.
The workaround for now is to add #EnableEurekaClient.
I reproduced and worked around the issue here: https://github.com/spencergibb/communityanswers/tree/so26450251
I have raised issue #35
I am using Spring boot 2.1.5 release.
Faced same issue.
Tried to launch hystrix dashboard using below url -
http://localhost:8082/hystrix.html
but it didn't work then I tried
http://localhost:8082/hystrix
and it worked.

Categories

Resources