Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 46242200C33 for ; Sat, 11 Mar 2017 08:20:30 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 449EA160B7B; Sat, 11 Mar 2017 07:20:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8B1B5160B5D for ; Sat, 11 Mar 2017 08:20:29 +0100 (CET) Received: (qmail 50913 invoked by uid 500); 11 Mar 2017 07:20:28 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 50902 invoked by uid 99); 11 Mar 2017 07:20:28 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Mar 2017 07:20:28 +0000 Received: from mail-ua0-f174.google.com (mail-ua0-f174.google.com [209.85.217.174]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 1972B1A06B6 for ; Sat, 11 Mar 2017 07:20:28 +0000 (UTC) Received: by mail-ua0-f174.google.com with SMTP id q7so115925881uaf.2 for ; Fri, 10 Mar 2017 23:20:27 -0800 (PST) X-Gm-Message-State: AMke39lD9D1cxYJQ3HvYYZuxg9iO5S6hXMwiAWlnewQ7XFuXbaQoE+DZc2URZjlIsI4c+vxWUtwrDkxjMCHqyQ== X-Received: by 10.159.39.167 with SMTP id b36mr12172721uab.86.1489216827050; Fri, 10 Mar 2017 23:20:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.107.193 with HTTP; Fri, 10 Mar 2017 23:20:06 -0800 (PST) In-Reply-To: <0ec060bb-db62-8da7-30cd-252a23eba037@uta.fi> References: <0ec060bb-db62-8da7-30cd-252a23eba037@uta.fi> From: Lukasz Lenart Date: Sat, 11 Mar 2017 08:20:06 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Problem reading a resource file (migrating 2.3.29 --> 2.5.10) To: Struts Users Mailing List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable archived-at: Sat, 11 Mar 2017 07:20:30 -0000 2017-03-11 0:21 GMT+01:00 Heikki Hyyr=C3=B6 : > Hi, > > I decided to migrate a Struts-based application from Struts 2.3.x to 2.5.= x. > The application worked without problems with Struts version 2.3.29. After > updating to 2.5.10, the application no longer seems to be able to read a > root-level resource file "package.properties": calling > getText("some.needed.property") results in an exception. > > Since this problem did not happen with 2.3.29, I wonder if the 2.5.x > versions have introduced a fundamental change in how the resource files a= re > handled? I was not able to find such information in the 2.3 --> 2.5 > migration guide. > > The problem occurs in the constructor of a database connection manager cl= ass > that tries to retrieve database information (driver information, database > url, and so on) from package.properties. A rough sketch of the class is > something like: > > public class DbConnectionManager extends ActionSupport > { > private DbConnectionManager() > { > String driverNames =3D getText("database.drivers"); // This throws a= n > exception in 2.5.10, but was ok in 2.3.29. > ... > } > } > > I suppose this problem could have something to do with the fact that this= is > a singleton class that is initialized only once during the lifetime of th= e > application? If this is the case, then what would a simple way to fix the > problem? A related question would be: how should I access resource files > from a non-action context (e.g. read resources in static initialization),= if > ActionSupport no longer permits it? This is do the changes in ActionSupport's dependencies, you must inject them first to have access to resource bundles. Instead your approach with singleton you can use something like this public class DbConnectionManager { public DbConnectionManager(@Inject TextProvider textProvider) { String driverNames =3D textProvider.getText("database.drivers"); ... } } and then public class MyAction extends ActionSupport { public String execute() { DbConnectionManager mgr =3D container.inject(DbConnectionManager.class) .... } } but perhaps the best option would be to disconnect your DAO layer from Web layer, you have coupled two different layers which is a "bad design" =E2=84=A2 Regards --=20 =C5=81ukasz + 48 606 323 122 http://www.lenart.org.pl/ --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org