Search in sources :

Example 1 with BeanCreationNotAllowedException

use of org.springframework.beans.factory.BeanCreationNotAllowedException in project spring-integration by spring-projects.

the class ManualFlowTests method testWrongIntegrationFlowScope.

@Test
public void testWrongIntegrationFlowScope() {
    try {
        new AnnotationConfigApplicationContext(InvalidIntegrationFlowScopeConfiguration.class).close();
        fail("BeanCreationNotAllowedException expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(BeanCreationNotAllowedException.class));
        assertThat(e.getMessage(), containsString("IntegrationFlows can not be scoped beans."));
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MessagingException(org.springframework.messaging.MessagingException) BeanCreationNotAllowedException(org.springframework.beans.factory.BeanCreationNotAllowedException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) Test(org.junit.Test)

Example 2 with BeanCreationNotAllowedException

use of org.springframework.beans.factory.BeanCreationNotAllowedException in project irida by phac-nml.

the class ForbidJpqlUpdateDeletePostProcessor method postProcessAfterInitialization.

/**
 * {@inheritDoc}
 */
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (beanName.endsWith("Repository") && bean instanceof EnversRevisionRepositoryFactoryBean) {
        logger.trace("Found a repository class... [" + beanName + "]");
        final EnversRevisionRepositoryFactoryBean factory = (EnversRevisionRepositoryFactoryBean) bean;
        try {
            final Iterable<Method> queryMethods = factory.getRepositoryInformation().getQueryMethods();
            for (final Method queryMethod : queryMethods) {
                if (queryMethod.isAnnotationPresent(Query.class) || queryMethod.isAnnotationPresent(Modifying.class)) {
                    final Query q = queryMethod.getAnnotation(Query.class);
                    final String queryValue = q.value().toLowerCase();
                    if (queryValue.contains("update") || queryValue.contains("delete")) {
                        throw new BeanCreationNotAllowedException(beanName, "Update and Delete are not allowed in JPQL because Envers doesn't audit those queries. Remove the update or delete from the method [" + queryMethod.getName() + "]");
                    }
                }
            }
        } finally {
        }
    }
    return bean;
}
Also used : Modifying(org.springframework.data.jpa.repository.Modifying) Query(org.springframework.data.jpa.repository.Query) BeanCreationNotAllowedException(org.springframework.beans.factory.BeanCreationNotAllowedException) Method(java.lang.reflect.Method) EnversRevisionRepositoryFactoryBean(org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean)

Aggregations

BeanCreationNotAllowedException (org.springframework.beans.factory.BeanCreationNotAllowedException)2 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 EnversRevisionRepositoryFactoryBean (org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean)1 Modifying (org.springframework.data.jpa.repository.Modifying)1 Query (org.springframework.data.jpa.repository.Query)1 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)1 MessagingException (org.springframework.messaging.MessagingException)1