WebLogic 12c - SpringBoot - java.io.FileNotFoundException: Could not open ServletContext resource
I am trying to deploy a SpringBoot project onto Weblogic 12c. According to this spring article I edited my SpringBootApplication class to implement WebApplicationInitializer interface.
I removed below lines from the POM
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.dependency.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Since there is no need for repackaging to executable archive.
I added below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Since I want to package the app as WAR file and I don't have a web.xml(I use annotation-based configuration) so I don't want the packaging to fail.
Also, I added below to set the packaging to WAR:
<packaging>war</packaging>
So far so good. I do mvn clean install and my WAR package is ready with all the dependencies as JAR files inside the WAR archive of my web app.
When I try to deploy this war file I get this error:
java.io.FileNotFoundException: Could not open ServletContext resource [/myfile.properties]
Could not open ServletContext resource [/myfile.properties]
I check if the mentioned properties file was in the package and there it was inside one of the JARs in the WAR file.
This is the structure of the JAR file:
META-INF
com
myfile.properties
So the properties file is in the root of the JAR archive as expected.
In that JAR archive one of the classes are trying to load the properties file using @PropertySource annotation as below:
@Configuration
@PropertySource("myfile.properties")
public class MyConfigClassForThisApp{
}
In another class the values are read as below:
@Value("${some.key}")
private String keyValue;
I understand that WebLogic classpath is not the same as the Tomcat classpath. So, I think I need to configure the WebLogic classpath to see this properties file. How can I do that?
OR maybe I should change the way I refer to this properties file and instead of using @PropertySource annotation, I should do something like:
this.getClass().getClassLoader().getResourceAsStream()
and wrap the properties file in a Properties class then read the values?
Please note that I would like to avoid changing the code whenever I can.
What would be the best way to make the WebLogic server see my configuration class with as little code/config modification as possible? Also, my WAR has other JARs inside and many of them have properties files like this. Whatever solution I can come up with will be applied multiple times for other properties files inside other JARs.
Note: I am deploying the application on a test environment on AdminServer.
Note: I placed the properties files in %WEBLOGIC_HOME%/user_projects/domains/MYDOMAIN as suggested here, it didn't work.
spring spring-boot weblogic weblogic12c
add a comment |
I am trying to deploy a SpringBoot project onto Weblogic 12c. According to this spring article I edited my SpringBootApplication class to implement WebApplicationInitializer interface.
I removed below lines from the POM
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.dependency.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Since there is no need for repackaging to executable archive.
I added below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Since I want to package the app as WAR file and I don't have a web.xml(I use annotation-based configuration) so I don't want the packaging to fail.
Also, I added below to set the packaging to WAR:
<packaging>war</packaging>
So far so good. I do mvn clean install and my WAR package is ready with all the dependencies as JAR files inside the WAR archive of my web app.
When I try to deploy this war file I get this error:
java.io.FileNotFoundException: Could not open ServletContext resource [/myfile.properties]
Could not open ServletContext resource [/myfile.properties]
I check if the mentioned properties file was in the package and there it was inside one of the JARs in the WAR file.
This is the structure of the JAR file:
META-INF
com
myfile.properties
So the properties file is in the root of the JAR archive as expected.
In that JAR archive one of the classes are trying to load the properties file using @PropertySource annotation as below:
@Configuration
@PropertySource("myfile.properties")
public class MyConfigClassForThisApp{
}
In another class the values are read as below:
@Value("${some.key}")
private String keyValue;
I understand that WebLogic classpath is not the same as the Tomcat classpath. So, I think I need to configure the WebLogic classpath to see this properties file. How can I do that?
OR maybe I should change the way I refer to this properties file and instead of using @PropertySource annotation, I should do something like:
this.getClass().getClassLoader().getResourceAsStream()
and wrap the properties file in a Properties class then read the values?
Please note that I would like to avoid changing the code whenever I can.
What would be the best way to make the WebLogic server see my configuration class with as little code/config modification as possible? Also, my WAR has other JARs inside and many of them have properties files like this. Whatever solution I can come up with will be applied multiple times for other properties files inside other JARs.
Note: I am deploying the application on a test environment on AdminServer.
Note: I placed the properties files in %WEBLOGIC_HOME%/user_projects/domains/MYDOMAIN as suggested here, it didn't work.
spring spring-boot weblogic weblogic12c
Don't remove thespring-boot-pugin
. It isn't just about making the archive executable it is also about adding things in the proper place when creating awar
. To load your properties just prefix withclasspath:
.
– M. Deinum
Nov 13 at 14:05
add a comment |
I am trying to deploy a SpringBoot project onto Weblogic 12c. According to this spring article I edited my SpringBootApplication class to implement WebApplicationInitializer interface.
I removed below lines from the POM
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.dependency.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Since there is no need for repackaging to executable archive.
I added below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Since I want to package the app as WAR file and I don't have a web.xml(I use annotation-based configuration) so I don't want the packaging to fail.
Also, I added below to set the packaging to WAR:
<packaging>war</packaging>
So far so good. I do mvn clean install and my WAR package is ready with all the dependencies as JAR files inside the WAR archive of my web app.
When I try to deploy this war file I get this error:
java.io.FileNotFoundException: Could not open ServletContext resource [/myfile.properties]
Could not open ServletContext resource [/myfile.properties]
I check if the mentioned properties file was in the package and there it was inside one of the JARs in the WAR file.
This is the structure of the JAR file:
META-INF
com
myfile.properties
So the properties file is in the root of the JAR archive as expected.
In that JAR archive one of the classes are trying to load the properties file using @PropertySource annotation as below:
@Configuration
@PropertySource("myfile.properties")
public class MyConfigClassForThisApp{
}
In another class the values are read as below:
@Value("${some.key}")
private String keyValue;
I understand that WebLogic classpath is not the same as the Tomcat classpath. So, I think I need to configure the WebLogic classpath to see this properties file. How can I do that?
OR maybe I should change the way I refer to this properties file and instead of using @PropertySource annotation, I should do something like:
this.getClass().getClassLoader().getResourceAsStream()
and wrap the properties file in a Properties class then read the values?
Please note that I would like to avoid changing the code whenever I can.
What would be the best way to make the WebLogic server see my configuration class with as little code/config modification as possible? Also, my WAR has other JARs inside and many of them have properties files like this. Whatever solution I can come up with will be applied multiple times for other properties files inside other JARs.
Note: I am deploying the application on a test environment on AdminServer.
Note: I placed the properties files in %WEBLOGIC_HOME%/user_projects/domains/MYDOMAIN as suggested here, it didn't work.
spring spring-boot weblogic weblogic12c
I am trying to deploy a SpringBoot project onto Weblogic 12c. According to this spring article I edited my SpringBootApplication class to implement WebApplicationInitializer interface.
I removed below lines from the POM
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.dependency.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Since there is no need for repackaging to executable archive.
I added below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Since I want to package the app as WAR file and I don't have a web.xml(I use annotation-based configuration) so I don't want the packaging to fail.
Also, I added below to set the packaging to WAR:
<packaging>war</packaging>
So far so good. I do mvn clean install and my WAR package is ready with all the dependencies as JAR files inside the WAR archive of my web app.
When I try to deploy this war file I get this error:
java.io.FileNotFoundException: Could not open ServletContext resource [/myfile.properties]
Could not open ServletContext resource [/myfile.properties]
I check if the mentioned properties file was in the package and there it was inside one of the JARs in the WAR file.
This is the structure of the JAR file:
META-INF
com
myfile.properties
So the properties file is in the root of the JAR archive as expected.
In that JAR archive one of the classes are trying to load the properties file using @PropertySource annotation as below:
@Configuration
@PropertySource("myfile.properties")
public class MyConfigClassForThisApp{
}
In another class the values are read as below:
@Value("${some.key}")
private String keyValue;
I understand that WebLogic classpath is not the same as the Tomcat classpath. So, I think I need to configure the WebLogic classpath to see this properties file. How can I do that?
OR maybe I should change the way I refer to this properties file and instead of using @PropertySource annotation, I should do something like:
this.getClass().getClassLoader().getResourceAsStream()
and wrap the properties file in a Properties class then read the values?
Please note that I would like to avoid changing the code whenever I can.
What would be the best way to make the WebLogic server see my configuration class with as little code/config modification as possible? Also, my WAR has other JARs inside and many of them have properties files like this. Whatever solution I can come up with will be applied multiple times for other properties files inside other JARs.
Note: I am deploying the application on a test environment on AdminServer.
Note: I placed the properties files in %WEBLOGIC_HOME%/user_projects/domains/MYDOMAIN as suggested here, it didn't work.
spring spring-boot weblogic weblogic12c
spring spring-boot weblogic weblogic12c
edited Nov 14 at 11:50
asked Nov 13 at 8:52
SoftwareTheory
5472722
5472722
Don't remove thespring-boot-pugin
. It isn't just about making the archive executable it is also about adding things in the proper place when creating awar
. To load your properties just prefix withclasspath:
.
– M. Deinum
Nov 13 at 14:05
add a comment |
Don't remove thespring-boot-pugin
. It isn't just about making the archive executable it is also about adding things in the proper place when creating awar
. To load your properties just prefix withclasspath:
.
– M. Deinum
Nov 13 at 14:05
Don't remove the
spring-boot-pugin
. It isn't just about making the archive executable it is also about adding things in the proper place when creating a war
. To load your properties just prefix with classpath:
.– M. Deinum
Nov 13 at 14:05
Don't remove the
spring-boot-pugin
. It isn't just about making the archive executable it is also about adding things in the proper place when creating a war
. To load your properties just prefix with classpath:
.– M. Deinum
Nov 13 at 14:05
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277106%2fweblogic-12c-springboot-java-io-filenotfoundexception-could-not-open-servle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277106%2fweblogic-12c-springboot-java-io-filenotfoundexception-could-not-open-servle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Don't remove the
spring-boot-pugin
. It isn't just about making the archive executable it is also about adding things in the proper place when creating awar
. To load your properties just prefix withclasspath:
.– M. Deinum
Nov 13 at 14:05