Foros de discusión

Liferay 7.0.3 don't generate spring BEANs for app when deploy WAR

Hamid Ehyaei, modificado hace 6 años.

Liferay 7.0.3 don't generate spring BEANs for app when deploy WAR

New Member Mensajes: 5 Fecha de incorporación: 21/05/12 Mensajes recientes
Hi all!
I have a portlet plugin project that uses its own Spring and Hibernate libraries and configurations. Its Service and DAO layers are Defined by spring annotations and the Model classes by Hibernate annotations. It uses the Ant builder to build the WAR file to be deployed on Liferay.
I have an org.springframework.web.WebApplicationInitializer class that initializes an application context to generate and collect beans, and a class defined by @Configuration and @ComponentScan annotations to scan the packages for beans, and a configuration class to generate Hibernate beans.
I use Spring v4.3.9 and Hibernate v5.2.10.
There is their codes:

@javax.servlet.annotation.HandlesTypes(WebApplicationInitializer.class)
public class SamfadWebApplicationInitializer implements WebApplicationInitializer {	
	@Override
	public void onStartup(ServletContext context) {
		try {
			AnnotationConfigApplicationContext confAppContext = new AnnotationConfigApplicationContext();
			confAppContext.register(HibernateConfiguration.class); //The configuration of the Hibernate beans and scan for @Entity classes.
			confAppContext.register(AppConfig.class); //The configuration of the Spring beans and scan for @Component classes.
			confAppContext.refresh();
		} catch (ClassNotFoundException | IllegalStateException | ServletException e) {
			e.printStackTrace();
		}
	}
}

@Configuration
@ComponentScan(basePackages = {"com.myBasePack", "com.company.proj"})
public class AppConfig implements SpringBeanDeclaration {
}


On the Liferay 7.0.2(ga3) when it was deployed (regardless of long time consuming), the confAppContext object scans the defined packages and sub packges and generates all beans.
On Liferay 7.0.3(ga4) when it was deployed , only the beans of the HibernateConfiguration and AppConfig classes are generated and the packages defined by the @ComponentScan aren't scanned and no beans are generated for any of their sub classes.

Can anyone help me to deploy this WAR on the Liferay 7.0.3 properly?
Thanks all.
thumbnail
Juan Gonzalez, modificado hace 6 años.

RE: Liferay 7.0.3 don't generate spring BEANs for app when deploy WAR

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
I think I was the one that fixed the ServletContainerInitializer bug.

So, servlet spec says it would scan files that uses a ServletContainerInitializer (previously defined in META-INF/services) that uses some of the declared HandleTypes, and then will execute this method:

void onStartup(java.util.Set<java.lang.class<?>&gt; collectedClasses,
               ServletContext ctx)
               throws ServletException</java.lang.class<?>

In your case, as seems you aren't using the Java EE standard procedure, it sounds like a Spring issue . Did you try adding

confAppContext.register(..)


with the class you are missing?
Hamid Ehyaei, modificado hace 6 años.

RE: Liferay 7.0.3 don't generate spring BEANs for app when deploy WAR

New Member Mensajes: 5 Fecha de incorporación: 21/05/12 Mensajes recientes
As you can see in the sample code, I used the WebApplicationInitializer interface that provide the onStartup(ServletContext context) method.
When this configuration was deployed on Liferay 7.0 ga3, it operates correctly and generates all beans defined by @ComponentScan but on Liferay 7.0 ga4 it doesn't.
Why this happened?
thumbnail
Juan Gonzalez, modificado hace 6 años.

RE: Liferay 7.0.3 don't generate spring BEANs for app when deploy WAR

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
Hamid Ehyaei:
As you can see in the sample code, I used the WebApplicationInitializer interface that provide the onStartup(ServletContext context) method.
When this configuration was deployed on Liferay 7.0 ga3, it operates correctly and generates all beans defined by @ComponentScan but on Liferay 7.0 ga4 it doesn't.
Why this happened?


This is Spring code, not Servlet 3 spec. code.

Check the things I said in my previous comment.

Thanks.
Alexander Ionov, modificado hace 6 años.

RE: Liferay 7.0.3 don't generate spring BEANs for app when deploy WAR

New Member Mensajes: 5 Fecha de incorporación: 31/01/18 Mensajes recientes
Hi, Hamid.
Did you manage to find any solution to this problem?