When I try to deploy file on server error occurs. I'm confused, because this code was working.
Exception
Failed to enable lec2ear-1.0.ear.
Unexpected HTTP response: 500
Request
{
"address" => [("deployment" => "lecture_7")],
"operation" => "deploy"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => {"JBAS014671: Failed services" => {"jboss.undertow.deployment.default-server.default-host./mart-parent" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./mart-parent: Failed to start service
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storageController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ru.menkin.ea.lec4.model.services.ICategoryService ru.menkin.ea.lec5.controllers.StorageController._categoryService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ru.menkin.ea.lec4.model.repositories.CategoryRepository ru.menkin.ea.lec4.model.services.CategoryService.categoryRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categoryRepository': Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/recipeDs
Error Code: 0
ICategoryService
public interface ICategoryService
{
public Category create(Category category);
public Category delete(int id) throws Exception;
public List<Category> findAll();
public Category update(Category category) throws Exception;
public Category findById(int id);
}
his implementation
public class CategoryService implements ICategoryService
{
#Autowired
private CategoryRepository categoryRepository;
...
Controller
#Controller
#RequestMapping(value = "/rest")
public class StorageController extends BaseController {
#Autowired
#Qualifier("categoryService")
private ICategoryService _categoryService;
...
database.xml
<djpa:repositories base-package="ru.menkin.ea.lec4.model" />
<bean id="categoryService" class="ru.menkin.ea.lec4.model.services.CategoryService" />
beans.xml
<context:annotation-config />
<context:component-scan base-package="ru.menkin.ea" />
Where my mistake?
Here last cause in your exception message:
Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException
Spring could not invoke the init method of your jpaMappingContext because a persistence exception occured - Something went wrong in the database.
So, Spring autowiring is actually working, but it cannot autowire your dependency because of a database problem that occurs when initializing one of the spring beans.
So something in the database or database settings changed since this code last worked. Analyze the full stack trace to find out the root cause of this issue - Which is a database problem.
Related
I'm using Spring Boot 1.5.2 and it has this annoying error which I could not understand the reason.
I have a Main class with these scanning configured:
#EnableJpaRepositories(basePackages = {"com.abc", "org.abc"})
#EntityScan(basePackages = {"com.abc", "org.abc", "abc"})
#ComponentScan(basePackages = {"com.abc", "org.abc", "abc"})
public class ApplicationMain extends SpringBootServletInitializer {
....
}
A model class
File: AbcUser.java
package com.abc.admin.model
#Entity
#Table(name = AbcUser.TABLE_NAME)
public class AbcUser {
}
And an interface class which extends CrudRepository:
File UserRespository.java inside this package.
package com.abc.repository.interfaces
#Repository
public interface UserRespository extends CrudRepository<AbcUser, Long> {
#Transactional
Long deleteByUsername(String username);
}
Now, when I tried to start the web application, it first has the warning which says, it cannot scand files...And then throws error, that the Bean cannot be found.
java -jar abc.war
WARN: Cannot search for matching files underneath URL [war:file:/home//tmp/build/applications/petascope/petascope_main/target/abc.war*/WEB-INF/classes/org/abc/] because it does not correspond to a directory in the file system
java.io.FileNotFoundException: URL [war:file:/home//tmp/build/applications/petascope/petascope_main/target/abc.war*/WEB-INF/classes/org/abc/] cannot be resolved to absolute file path because it does not reside in the file system: war:file:/home//tmp/build/applications/petascope/petascope_main/target/abc.war*/WEB-INF/classes/org/abc/
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:218)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
at org.springframework.core.io.UrlResource.getFile(UrlResource.java:213)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:685)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:477)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:279)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.buildDefaultPersistenceUnitInfo(DefaultPersistenceUnitManager.java:525)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.readPersistenceUnitInfos(DefaultPersistenceUnitManager.java:505)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:442)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:426)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:325)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
at org.abc.MigrationBeanApplicationConfiguration.createEntityManagerFactory(MigrationBeanApplicationConfiguration.java:313)
Due to it cannot create Bean
ERROR [2021-08-23 16:32:17] TomcatStarter#63: Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'requestsFilter': Unsatisfied dependency expressed through field 'userRepositoryService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRepositoryService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRespository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.rasdaman.admin.model.RasdamanUser
WARN [2021-08-23 16:32:17] AnnotationConfigEmbeddedWebApplicationContext#550: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
ERROR [2021-08-23 16:32:17] SpringApplication#815: Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRespository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.abc.admin.model.AbcUser
I found the solution for the scanning problem which leads to the error of Bean not found from https://shekerama.wordpress.com/2017/03/25/how-to-solve-java-lang-illegalargumentexception-not-an-managed-type/.
final LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPackagesToScan("com.abc", "org.abc");
DEBUG [http-bio-8004-exec-3] DispatcherServlet.processRequest(954) |
Could not complete request
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'contactFormController': Injection of
autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire method: public void
com.crisil.cmd.webapp.controller.ContactFormController.setContactListService(com.crisil.cmd.service.ContactListService);
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'contactListService': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire method: public void
com.crisil.cmd.service.impl.ContactListServiceImpl.setContactListDao(com.crisil.cmd.dao.ContactListDao);
nested exception is java.lang.NoClassDefFoundError:
org/apache/kafka/clients/producer/Callback at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
the above code is from my project which is in production ,so there are no chance of java errors (#AUTOWIRED ) OR annotation based errors , my question is , is there any other possibility of getting this type of error .
As the title states I'm trying to deploy a spring boot application to heroku.
Under /resources I have an application.yml file from which I inject properties using #Value annotation.
During boot I get a stacktrace but I believe the relevant part is the below
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dk.fitfit.remotetexting.util.GoogleAuth dk.fitfit.remotetexting.api.controller.MessageController.googleAuth; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'googleAuth': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dk.fitfit.remotetexting.business.service.ConfigurationService dk.fitfit.remotetexting.util.GoogleAuth.configurationService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String dk.fitfit.remotetexting.business.service.ConfigurationService.clientId; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'security.oauth2.client.clientId' in string value "${security.oauth2.client.clientId}"
Basically it says it can't create my ConfigurationService because it can't resolve my placeholder 'security.oauth2.client.clientId'.
#Service
public class ConfigurationService {
#Value("${security.oauth2.client.clientId}")
private String clientId;
#Value("${fcm.auth_key}")
private String AUTH_KEY_FCM;
#Value("${fcm.api_url}")
private String API_URL_FCM;
...
}
Any clues about how to make heroku use my application.yml file?
I forgot to include application.yml file in my repository... doh!
I have some #Component and #Resource in my SpringBoot application.
I have the right JDBC datasource, and also I have some REST services, by Jersey.
I want to test one of the services, but it will fail, it says:
Injection of autowired dependencies failed
But it does not use any component.
This is a simple test for testing db, and it is working:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = MyApplication.class)
public class CommonRepositoryTest {
#Autowired
private MyRepository myRepository;
#Test
public void testDatabaseChangeLogsSize() {
int resultSize = myRepository.getTableRowSize(MyTable.TABLE_NAME);
System.out.println("MyTable result list size: "+resultSize);
assertTrue("MyTable table should has at least one row!", resultSize>0);
}
}
But this REST tester is not working:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = MyApplication.class)
public class SampleResourceTest extends JerseyTest {
#Override
protected Application configure() {
ApplicationContext context = new AnnotationConfigApplicationContext(MyApplication.class);
return new ResourceConfig(SampleResource.class).property("contextConfig", context);
}
#Test
public void testSampleGet() throws Exception {
long id = 1;
String name = "name";
SampleDomainModel sampleDomainModel = new SampleDomainModel();
sampleDomainModel.setId(id);
sampleDomainModel.setName(name);
Response response = target("/sampleresource/samplepath/" + id).queryParam(name).request().get(Response.class);
SampleDomainModel responseSampleDomainModel = response.readEntity(SampleDomainModel.class);
assertEquals(sampleDomainModel.getId(), responseSampleDomainModel.getId());
}
}
As you see, it must override the configure() method from JerseyTest.
I think the problam is, that the AnnotationConfigApplicationContext cannot load anything maybe (?).
The #SpringApplicationConfiguration(classes = MyApplication.class) annotation loads the context, but the new AnnotationConfigApplicationContext(MyApplication.class) code maybe do the failure, it does not have the full context.
If I replace the code with mocking, it works (but it is not a nice way):
#Override
protected Application configure() {
ApplicationContext mockContext = Mockito.mock(ApplicationContext.class);
return new ResourceConfig(SampleResource.class).property("contextConfig", mockContext);
}
The fail message is:
2016-05-13 13:25:39.617 WARN 9832 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRepositoryImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.repository.impl.myRepositoryImpl.jdbcTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': 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.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.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/DataSourceAutoConfiguration$NonEmbeddedConfiguration.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.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).
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.422 sec <<< FAILURE! - in com.ws.server.SampleResourceTest
testSampleGetWithCorrectParameters(com.ws.server.SampleResourceTest) Time elapsed: 0.015 sec <<< ERROR!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRepositoryImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.repository.impl.MyRepositoryImpl.jdbcTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': 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.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.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/DataSourceAutoConfiguration$NonEmbeddedConfiguration.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.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.getDriverClassName(DataSourceProperties.java:180)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:121)
How to use the SpringBoot context for this jersey test?
SImply put, you can't use both Spring's TestContext and Jersey Test Framework together. They will operate on two different ApplicationContexts. Even if you try to inject the ApplicationContext (created be the TestContext) into the test class and pass it to the ResourceConfig in the configure method, it's too late, as the injection doesn't occur until after construction, but the `configure method is called during contruction.
Forget JerseyTest and just use #WebIntegrationTest. See the sample from the spring boot project.
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(SampleJerseyApplication.class)
#WebIntegrationTest(randomPort = true)
public class SampleJerseyApplicationTests {
#Value("${local.server.port}")
private int port;
In a Jersey/Boot environment, Jersey needs to run in a web app environment, and that's what the #WebIntegrationTest does.
For the client, instead of just calling target on the JerseyTest, you will just need to create the client
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:" + this.port);
Response response = target.path("/sampleresource/samplepath/" + id).request().get();
I have java spring application which uses spring 3.0.7 with the following spring jars
spring-aop-3.0.7.RELEASE.jar
spring-asm-3.0.7.RELEASE.jar
spring-beans-3.0.7.RELEASE.jar
spring-context-3.0.7.RELEASE.jar
spring-core-3.0.7.RELEASE.jar
spring-data-jdbc-core-1.0.0.RELEASE.jar
spring-expression-3.0.7.RELEASE.jar
spring-jdbc-3.0.7.RELEASE.jar
spring-tx-3.0.7.RELEASE.jar
spring-web-3.0.7.RELEASE.jar
This application is working fine in many of the VMs. But in one VM it throws the following exception while the server starts up.
Exception sending context initialized event to listener instance of
class org.springframework.web.context.ContextLoaderListener
Any pointers is appreciated.
Entire exception stacktrace:
INFO: Initializing Spring root WebApplicationContext
May 13, 2015 3:28:01 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testCacheLoader': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.util.localization.LoadLocaleMessage com.caching.testCacheLoader.llm; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadLocaleMessage': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.common.dao.CommonDAO com.util.localization.LoadLocaleMessage.commonDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.caching.testCache com.common.dao.CommonDAOImpl.testCache; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testCache': Invocation of init method failed; nested exception is com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
#PostConstruct
public void init() {
cache = CacheBuilder.newBuilder().maximumSize(100)
.refreshAfterWrite(8, TimeUnit.HOURS).removalListener(listener)
.build(loader);
ScheduledExecutorService ses = Executors
.newSingleThreadScheduledExecutor();
ses.scheduleWithFixedDelay(new Runnable() {
public void run() {
for (String key : cache.asMap().keySet()) {
cache.refresh(key);
logger.info("Refreshing cache . . . . ");
}
}
}, 0, 5, TimeUnit.MINUTES);
try {
cache.get("LOCALIZATION");
} catch (ExecutionException e) {
e.printStackTrace();
}
}
Look at the last part of the exception:
Error creating bean with name 'testCache':
Invocation of init method failed; nested exception is
com.google.common.util.concurrent.UncheckedExecutionException:
java.lang.NullPointerException
How does the init-method of your testCache bean look - that's where the fault is (a NullPointerException).
Cheers,