Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require bean classes to be available when current profile is inactive [SPR-8777] #13420

Closed
spring-projects-issues opened this issue Oct 14, 2011 · 3 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression)

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 14, 2011

Matthew T. Adams opened SPR-8777 and commented

When using bean profiles, all classes of all beans must be available whether or not the bean is activated as a result of the activation of the profile that it belongs to.

I discovered this by using a Maven profile to build a sample project that includes dependencies based on Maven profile(s). In my case, I'm switching between DataNucleus & Hibernate at build and test time. When the Maven profile for DataNucleus is activated, the DataNucleus dependencies are included; the Maven profile for Hibernate, the Hibernate dependencies.

In my application context config, I have a bean for a Hibernate & DataNucleus EMF:

<beans profile="hib">
    <bean id="emf"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        p:dataSource-ref="dataSource">
        <property name="jpaVendorAdapter">
            <bean
                class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                p:showSql="true">
            </bean>
        </property>

        <property name="jpaProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
                hibernate.connection.pool_size=0
                hibernate.temp.use_jdbc_metadata_defaults=false
                hibernate.hbm2ddl.auto=none
            </value>
        </property>
    </bean>
</beans>

<beans profile="dn">
    <bean id="emf"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        p:persistenceProviderClass="org.datanucleus.api.jpa.PersistenceProviderImpl"
        p:dataSource-ref="dataSource">

        <property name="jpaProperties">
            <value>
                datanucleus.jpa.addClassTransformer=false
                datanucleus.autoCreateSchema=false
                datanucleus.storeManagerType=rdbms
                datanucleus.rdbms.datastoreAdapterClassName=org.datanucleus.store.rdbms.adapter.MySQLAdapter
                datanucleus.rdbms.checkExistTablesOrViews=false
                datanucleus.rdbms.omitDatabaseMetaDataGetColumns=true
            </value>
        </property>
    </bean>
</beans>

Problem is, when the "dn" profile is active, the container throws an exception because the Hibernate dependencies are not available:

Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence

If this profile is not activated, why should the bean classes mentioned in it need to be available?


Affects: 3.1 RC1

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 17, 2011

Chris Beams commented

Hey Matthew,

Will need to look further, but at a glance, this certainly shouldn't be happening. Bean definitions are not registered at all if during parsing we notice an enclosing <beans profile="xyz"> element where 'xyz' is not currently active.

It would be a big help if you can reproduce this in the small. Check out https://github.com/SpringSource/spring-framework-issues#readme if you're not already familiar.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 18, 2011

Matthew T. Adams commented

Can't repro with a small test project. Something else must've been going on. Go ahead and close this issue. I'll comment again if I figure out the juju to repro.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 18, 2011

Chris Beams commented

Ok - thanks for giving a shot at reproduction.

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) and removed type: enhancement A general enhancement labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression)
Projects
None yet
Development

No branches or pull requests

1 participant