struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: Problem reading a resource file (migrating 2.3.29 --> 2.5.10)
Date Sat, 11 Mar 2017 07:20:06 GMT
2017-03-11 0:21 GMT+01:00 Heikki Hyyrö <heikki.hyyro@uta.fi>:
> 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 are
> 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 class
> 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 = getText("database.drivers");  // This throws an
> 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 the
> 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 = textProvider.getText("database.drivers");
    ...
  }
}

and then

public class MyAction extends ActionSupport {

  public String execute() {
    DbConnectionManager mgr = 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" ™


Regards
-- 
Łukasz
+ 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


Mime
View raw message