@@ -201,28 +201,6 @@ public abstract class VaadinService implements Serializable {
201201 */
202202 public VaadinService (DeploymentConfiguration deploymentConfiguration ) {
203203 this .deploymentConfiguration = deploymentConfiguration ;
204-
205- final String classLoaderName = getDeploymentConfiguration ()
206- .getClassLoaderName ();
207- if (classLoaderName != null ) {
208- try {
209- final Class <?> classLoaderClass = getClass ().getClassLoader ()
210- .loadClass (classLoaderName );
211- final Constructor <?> c = classLoaderClass
212- .getConstructor (ClassLoader .class );
213- setClassLoader ((ClassLoader ) c .newInstance (
214- new Object [] { getClass ().getClassLoader () }));
215- } catch (final Exception e ) {
216- throw new RuntimeException (
217- "Could not find specified class loader: "
218- + classLoaderName ,
219- e );
220- }
221- }
222-
223- if (getClassLoader () == null ) {
224- setDefaultClassLoader ();
225- }
226204 }
227205
228206 /**
@@ -246,6 +224,7 @@ protected VaadinService() {
246224 * if a problem occurs when creating the service
247225 */
248226 public void init () throws ServiceException {
227+ doSetClassLoader ();
249228 instantiator = createInstantiator ();
250229
251230 // init the router now so that registry will be available for
@@ -2408,4 +2387,29 @@ public static String getCsrfTokenAttributeName() {
24082387 return VaadinSession .class .getName () + "."
24092388 + ApplicationConstants .CSRF_TOKEN ;
24102389 }
2390+
2391+ private void doSetClassLoader () {
2392+ final String classLoaderName = getDeploymentConfiguration () == null
2393+ ? null
2394+ : getDeploymentConfiguration ().getClassLoaderName ();
2395+ if (classLoaderName != null ) {
2396+ try {
2397+ final Class <?> classLoaderClass = getClass ().getClassLoader ()
2398+ .loadClass (classLoaderName );
2399+ final Constructor <?> c = classLoaderClass
2400+ .getConstructor (ClassLoader .class );
2401+ setClassLoader ((ClassLoader ) c .newInstance (
2402+ new Object [] { getClass ().getClassLoader () }));
2403+ } catch (final Exception e ) {
2404+ throw new RuntimeException (
2405+ "Could not find specified class loader: "
2406+ + classLoaderName ,
2407+ e );
2408+ }
2409+ }
2410+
2411+ if (getClassLoader () == null ) {
2412+ setDefaultClassLoader ();
2413+ }
2414+ }
24112415}
0 commit comments