I am trying to create a simple Spring application with Teradata database.
It was working with mySql database and driver but after changing to Teradata driver/databased i receive following exception :
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': 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$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 java.lang.IllegalArgumentException: URL must start with 'jdbc'
Application Properties :
spring.datasource.url =jdbc:teradata://servername/db
spring.datasource.username = dbc
spring.datasource.password = dbc
spring.datasource.driverClassName=com.ncr.teradata.TeraDriver
I think that is problem of Spring you might be using #Autowire on constructor but spring can't inject class with that name. To solve the problem, just define a DataSource in your context - at which point Spring will be able to inject the bean and correctly bootstrap the context.
Related
I have the following value configured in my SQS Listener in springboot. The queue is configured only for DEV and STAGE environments. So I want to disable it in my local after testing. How do i achieve that?
#SqsListener(value = { "${cloud.aws.endpoint}" } , deletionPolicy =SqsMessageDeletionPolicy.ON_SUCCESS)
public void processMessage(String message) throws Exception {
}
I tried to add the following to my application-local.xml(to keep it local), but it didn't work. Anyone went through the same scenario?
autoconfigure:
exclude:
- org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
I am getting the following error everytime.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stackResourceRegistryFactoryBean' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Unsatisfied dependency expressed through method 'stackResourceRegistryFactoryBean' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoDetectingStackNameProvider' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackNameProvider]: Factory method 'autoDetectingStackNameProvider' threw exception; nested exception is java.lang.IllegalArgumentException: No valid instance id defined
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:799) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
com.amazonaws.SdkClientException: Failed to connect to service endpoint:
at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100) [aws-java-sdk-core-1.11.867.jar:na]
Caused by: java.net.ConnectException: Host is down (connect failed)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoDetectingStackNameProvider' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackNameProvider]: Factory method 'autoDetectingStackNameProvider' threw exception; nested exception is java.lang.IllegalArgumentException: No valid instance id defined
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.sprin
I've faced similar issues while using #SqsListener. What I usually do is comment out the annotation when running the app locally - it's ugly but it works.
#Autowired
private Configuration freemarkerConfig;
Getting the following exception,
Unsatisfied dependency expressed through field 'freemarkerConfig';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'freeMarkerConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/freemarker/FreeMarkerServletWebConfiguration.class]: Unsatisfied dependency expressed through method 'freeMarkerConfiguration' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'freeMarkerConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/freemarker/FreeMarkerServletWebConfiguration.class]: Invocation of init method failed;
nested exception is freemarker.core.Configurable$UnknownSettingException: Unknown FreeMarker configuration setting: "recognize_standard_file_extensions"
I had the same issue, make sure you are autowiring correct FreeMarker Configuration, or use
#Autowired
private freemarker.template.Configuration freeMarker;
#RepositoryRestResource(path = "/region", collectionResourceRel = "list", excerptProjection = CustomRegion.class)
public interface RegionRepository extends JpaRepository<Region, Integer> {
}
data rest class
#SpringBootApplication
public class ProfUzApplication {
public static void main(String[] args) {
SpringApplication.run(ProfUzApplication.class, args);
}
}
main running class
Occured error
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repositorySearchController' defined in URL [jar:file:/C:/Users/saidk/.m2/repository/org/springframework/data/spring-data-rest-webmvc/3.2.1.RELEASE/spring-data-rest-webmvc-3.2.1.RELEASE.jar!/org/springframework/data/rest/webmvc/RepositorySearchController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityLinks' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.webmvc.support.RepositoryEntityLinks]: Factory method 'entityLinks' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is java.lang.IllegalStateException: Path /region configured for uz.pdp.prof.repository.RegionRepository must only contain a single path segment!
You have to mention path='endpoint name' without using '/' in #RepositoryRestResource. You have to use #RepositoryRestResource(path = "region"), it's direct spring MVC to create RESTful endpoints at /region
The problem is happening because you defined the path using "/". Spring does not allow us to define a composed path like "/api/v1/my_entity". Just remove the "/" from your path and it will work.
I created a new project based on 2.2.2 a couple days ago and got the same issue.
After a few tries, the way to fix it is to use the same value in path and collectionResourceRel. In your case, try to use "region" in both path and collectionResourceRel.
I am trying to connect to Oracle DB.
When I try to connect through simple jdbc connection it works.
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:#chbsux0097.eu.novartis.net:1530:AD14", "xxxx", "xxxxx")
However, it's not working with Spring-boot with below error
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-05-09 12:48:51.189 ERROR 16236 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactoryBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.RuntimeException: Driver oracle.jdbc.OracleDriver claims to not accept jdbcUrl, jdbc:oracle:thin#chbsux0097.eu.novartis.net:1530:AD14
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
application.properties
spring.datasource.username=xx
spring.datasource.password=xxxxx
spring.datasource.url=jdbc:oracle:thin#chbsux0097.eu.novartis.net:1530:AD14
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
You're missing a colon in the URL after thin in your config. It needs to be:
spring.datasource.url=jdbc:oracle:thin:#chbsux0097.eu.novartis.net:1530:AD14
Note that the colon is present in your working simplified example.
I'm getting an error -
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'netLogsDao': Injection of resource dependencies failed; nested
exception is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'abcDataSource' defined in
com.kinsale.submclrmgr.config.DataConfig: Bean instantiation via factory
method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[javax.sql.DataSource]: Factory method 'abcDataSource' threw exception;
nested exception is
org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:
Failed to look up JNDI DataSource with name 'dataSource/abc'; nested
exception is javax.naming.NameNotFoundException: Name [dataSource/abc] is
not bound in this Context. Unable to find [dataSource].
I am trying to figure out how to bind my data source, however the documentation I've found isn't helpful. there is a JndiTemplate that I can use to bind the data source, passing the parameters of String name and Object object, but nothing I can find tells me anything about the object.
What is the object that I bind to the name of the data source? And is it the name of the Bean I am creating or the name of the Resource in the context.xml?
Here is the Bean -
#Bean(name="abcDataSource")
public DataSource abcDataSource(){
JndiDataSourceLookup jndi = new JndiDataSourceLookup();
jndi.setResourceRef(true);
return jndi.getDataSource("dataSource/abc");
Here is the use of the bean -
#Resource(name="abcDataSource")
private DataSource ds;
Here is the context.xml entry (I do have the correct username and password)-
<Resource
name="dataSource/abc"
auth="Container"
type="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
factory="org.apache.naming.factory.BeanFactory"
URL="jdbc:mysql://abc/db_netlogs" />
In order for this to work, the following dependency needs to be in the pom.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
</dependency>
As soon as I added that, everything worked.