struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Khurram (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4758) @autowired does not work since Struts 2.3.28.1
Date Wed, 15 Mar 2017 22:58:41 GMT

    [ https://issues.apache.org/jira/browse/WW-4758?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15927138#comment-15927138
] 

Khurram commented on WW-4758:
-----------------------------

{code:java}
1)
public abstract class BasePreparer implements ViewPreparer {
	protected final Logger LOG = Logger.getLogger(this.getClass());
	public void execute(TilesRequestContext tilesContext, AttributeContext attributeContext)
{
		boolean display = performPreparer(tilesContext, attributeContext);

2)
public class LandingSummaryPreparer extends BasePreparer {
	@Autowired
	private Services services;
	@Override
	protected boolean performPreparer(TilesRequestContext tilesContext, AttributeContext attributeContext)
{
		HttpServletRequest request = getRequest(tilesContext);

3)Service.class
import org.springframework.beans.factory.annotation.Autowired;
public class Services {
	@Autowired
	private UserService userService;
	public UserService getUserService() {
		return userService;
	}
		
4)
In tiles.xml
 <definition name="v3.landing.summary" extends="v3.basepage" template="/WEB-INF/struts/v3/tiles/landingpages/summarywithfollow.jsp"
    			preparer="au.com.presentation.struts.action.v3.tiles.landing.LandingSummaryPreparer"
/>

5) applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="au.com" />
<bean id="userService" class="au.com.business.service.impl.UserServiceImpl" />
<bean id="services" class="au.com.business.service.Services" />
<bean id="cacheLocator" class="au.com.support.cache.CacheLocator">
		<constructor-arg ref="lasooServices" />
		<constructor-arg ref="XMemCachedExternalCache" />
		<constructor-arg ref="assetUpdateMonitor" />
		<constructor-arg ref="elasticSearchFactory" />
</bean>
<bean class="au.com.support.site.ServiceLocator">
	<constructor-arg ref="services" />
</bean>				

6) In web.xml
<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
7) In struts.xml
<constant name="struts.objectFactory" value="spring" />		
{code}

> @autowired does not work since Struts 2.3.28.1 
> -----------------------------------------------
>
>                 Key: WW-4758
>                 URL: https://issues.apache.org/jira/browse/WW-4758
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Spring
>    Affects Versions: 2.3.28
>            Reporter: Khurram
>             Fix For: 2.5.next
>
>
> I am trying to run on Tomcat a Spring 4 + Struts 2 + Hibernate web app, but it fails
to start with NullPointerException for autowired field. This issue is happening after release
of 2.3.28.1 So please help
> 2017-03-15 15:28:35,308 [http-bio-8009-exec-1] ERROR au.com.presentation.struts.action.tiles.landing.LandingSummaryPreparer
- Error Id:
> java.lang.NullPointerException
> 	at au.com.presentation.struts.action.tiles.landing.LandingSummaryPreparer.performPreparer(LandingSummaryPreparer.java:142
> and in my code I have autowired that always returning null
> @Autowired
> private Services services;



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message