I'm developping a spring boot application and it works fine when I run the command:
mvn spring-boot:run
But when deploying jar file with the command:
java -jar target\jarfile.jar
I get the following error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeResource': Unsatisfied dependency expressed through field 'hrServicesSilo'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hrServicesSilo': Unsatisfied dependency expressed through field 'employeeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeService': Unsatisfied dependency expressed through field 'employeeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.intranet.si.model.hr.Employee
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]
What am I doing wrong?
I can see a repository so I assume you use spring-data. It is strange that it works in maven and not working after packaging so you can try the following:
Check that you use spring-maven-plugin to package your application.
Try to add #EntityScan("com.intranet.si.model.hr") (can also be com.intranet.si.model to recursivly catch all models in the package and sub-packages) to one of your configuration classes or to the application class (the one annotated with #SpringBootApplication). This will notify spring + hibernate where to scan for entities. Also make sure your entity is annotated with #Entity.
I guess that you already have #EnableJpaRespotories in one of your configuration files but make sure it is configured as well.
Related
I faced the problem that during execution of my Spring Boot app in IntelliJ IDEA (Java) all works fine. But when I created jar file and tried to run the app in console, I have UnsatisfiedDependencyException because could not resolve placeholder.
Detailed description of Exception is below:
WARN org.springframework.context.annotation.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'controllerBattle': Unsatisfied dependency expressed through field 'controllerMarket'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'controllerMarketBean': Unsatisfied dependency expressed through field 'meteorRain'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'meteorRainBean': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'priceMeteorRain' in value "${priceMeteorRain}"
I researched this problem and found similar problem raised 2 years ago:
Spring boot Could not resolve placeholder
But it was related to kotlin and it was left unsolved.
Are there ways to solve this problem for Java?
I'll be grateful for your help.
I have built a java application using spring-boot and maven. When I am running this application from eclipse it is running perfectly fine, but when I try to run this application as a standalone jar through java -jar, it is giving me this error
Error
o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'placeRefillOrderControllerImpl':
Unsatisfied dependency expressed through field 'placeRefillOrderService'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException
Error creating bean with name 'placeRefillOrderServiceImpl':
Unsatisfied dependency expressed through field 'placeRefillOrderBiz'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'placeRefillOrderBizImpl':
Unsatisfied dependency expressed through field 'placeRefillOrderConnector'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'getConnector': Unsatisfied dependency expressed through field 'refillOrderRequestTransformer'; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'refillOrderRequestTransformer':
Lookup method resolution failed; nested exception is
java.lang.IllegalStateException: Failed to introspect Class [com.sams.pharmacy.soapconnector.helper.RefillOrderRequestTransformer] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader#439f5b3d]
I am getting this error while trying to deploy spring boot 1.4.2 application to tomcat 7 :
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationServiceImpl': Unsatisfied dependency expressed through field 'applicationDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDao' defined in file [E:\sources\apache-tomcat-7.0.86\webapps\OnlineChannelBackend-0.0.1-SNAPSHOT\WEB-INF\classes\com\pack\dao\ApplicationDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$f214bdd7]: Constructor threw exception; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'java.lang.Object' available: expected single matching bean but found 4: &applicationDao,systemEnvironment,contextParameters,contextAttributes
my related build gradle :
sourceCompatibility = 1.6 //java6
targetCompatibility = 1.6
dependencies {
compile('org.springframework.boot:spring-boot-legacy:1.1.0.RELEASE')
compile('org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2')
compile('com.oracle:ojdbc6:11.1.0.7.0') //java6
providedRuntime('org.apache.tomcat:tomcat-juli:7.0.59') // java6
compile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '7.0.59'
and In com.pack.dao I have 3 mapper interfaces annotated with #Mapper and corresponding xml files in corresponding folder in resources ... the application was running fine with spring boot 2 but once I started changing it to spring boot 1.4.2 I couldn't get it to work
Because it was working in previous spring version, i believe you have your configuration files, so you may need to exclude spring auto configurer for my batis.
#SpringBootApplication
#EnableAutoConfiguration(exclude = {MybatisAutoConfiguration.class})
I am attempting to this tutorial: http://spring.io/guides/tutorials/bookmarks/
I have successfully created a Rest Controller and run it through eclipse, and I'm able to get a JSON response in the browser. I have used an Apache Derby embedded database.
What I'd like to do now is run it on my separate Tomcat instance (not embedded), with a JNDI lookup to a MySQL database.
The tutorial mentioned above does not mention JNDI, so I looked here instead, which suggested adding
spring.datasource.jndi-name=java:comp/env/jdbc/mydb
to the application.properties file.
I'm pretty sure I have Tomcat set up correctly, as I've used the JNDI lookup before in another app, but attempting to build the WAR using Maven fails:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/finance'; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
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)
....
It seems the tutorials are not complete, or have I missed something? I'm at a loss as to how to proceed.
I get an error when I want to import my project to sts(eclipse). I generate this project with spring roo and its work an other laptop so I just want to import and run on tomcat server somebody know what is this, I watch the dependecies and this class is there (I use Windows):
2012-10-16 23:32:42,540 [main] ERROR
org.springframework.web.context.ContextLoader - Context initialization
failed org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'transactionManager' defined in file
[D:\projects.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\roo-jquery-bootstrap\WEB-INF\classes\META-INF\spring\applicationContext.xml]:
Cannot resolve reference to bean 'entityManagerFactory' while setting
bean property 'entityManagerFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'entityManagerFactory' defined in file
[D:\projects.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\roo-jquery-bootstrap\WEB-INF\classes\META-INF\spring\applicationContext.xml]:
Invocation of init method failed; nested exception is
java.lang.IllegalArgumentException: Cannot find class
[org.hibernate.ejb.HibernatePersistence] at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at
... 41 more
I solved that it was an eclipse bug i restarted the eclipse and the application worked..