Html 如何从应用程序的类路径运行静态内容以使用(SpringBoot 2.x+;weblogic+;*.war)?
我有一个weblogic服务器,我在Innellij Idea中遇到它,用于应用程序的审计工作。 我基于SpringBoot 2.x制作了一个web应用程序。我正在使用Intellij Idea 2019,在那里我在weblogic 12.x上配置了部署我的Web应用程序 pom.xmlHtml 如何从应用程序的类路径运行静态内容以使用(SpringBoot 2.x+;weblogic+;*.war)?,html,spring-boot,weblogic12c,Html,Spring Boot,Weblogic12c,我有一个weblogic服务器,我在Innellij Idea中遇到它,用于应用程序的审计工作。 我基于SpringBoot 2.x制作了一个web应用程序。我正在使用Intellij Idea 2019,在那里我在weblogic 12.x上配置了部署我的Web应用程序 pom.xml 4.0.0 org.springframework.boot 所以,它起作用了 但是我需要更复杂的静态内容,我想把它放到一个应用程序类路径中 我做了很多 src/main/resources/templat
4.0.0
org.springframework.boot
所以,它起作用了
但是我需要更复杂的静态内容,我想把它放到一个应用程序类路径中
我做了很多
src/main/resources/templates/pages/index.html
你好Weblogic!!!
你好Weblogic!!!
src/main/resources/static/css/style.css
.st{
颜色:红色;
字体大小:35px;
}
然后
src/main/java/com/weblogic/weblogic/mvc/config/MyMvcConfig.java
包com.weblogic.weblogic.mvc.config;
导入org.springframework.context.annotation.Configuration;
导入org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
导入org.springframework.web.servlet.config.annotation.WebMVCConfiguer;
@配置
公共类MyMvcConfig实现WebMVCConfiguer{
@凌驾
public void addResourceHandlers(ResourceHandlerRegistry注册表){
registry.addResourceHandler(
“/static/css/**”,
“/templates/pages/**”)
.addResourceLocations(
“类路径:/”,
“类路径:/static/css/”,
“类路径:/templates/pages/”;
}
}
但我得到…错误500——内部服务器错误
位于的java.lang.NullPointerException
weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:738)
在
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:796)
在
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:713)
在
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.SendErrorIfEssential(ErrorPageFilter.java:349)
在
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.getWriter(ErrorPageFilter.java:363)
在
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$StaticView.render(ErrorMvcAutoConfiguration.java:227)
在
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373)
在
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118)
在
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057)
在
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
在
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
谁知道如何解决这个问题呢?您必须使用“模板引擎”–Thymeleaf。它没有任何其他的工作方式(我想使用纯(html+bootstrap),但不清楚如何配置它)
- pom.xml
无法应用这些设置
- 配置文件-*.xml
src/main/webapp/WEB-INF/WEB.xml
如果缺少此文件,则部署会发生错误(在开发环境中,您可以在控制台中看到)
src/main/webapp/WEB-INF/weblogic.xml
rst
org.slf4j
rst
在这里,在为应用程序的根上下文选择名称时需要小心(例如,如果为上下文选择名称-/web,->将出现错误,因为此名称保留在某个位置)
@SpringBootConfiguration
@启用自动配置
@组件扫描
公共类WebSpringBootJarApplication扩展了SpringBootServletilizer实现了WebApplicationInitializer{
公共静态void main(字符串[]args){
run(WebSpringBootJarApplication.class,args);
}
@凌驾
受保护的SpringApplicationBuilder配置(SpringApplicationBuilder){
返回builder.sources(WebSpringBootJarApplication.class);
}
}
- @SpringBoot配置
- @启用自动配置
- @组件扫描
- 您必须有这3个注释,否则将无法工作
文档中说,@SpringBootConfiguration取代了注释:
- @配置
- @启用自动配置
- @组件扫描
@SpringBootConfiguration-表示此类提供应用程序
SpringBoot
它也可以用作@配置注释的替代,因为可以自动找到配置
@EnableAutoConfiguration-通过扫描类路径组件并注册匹配不同条件的bean,启用Spring ApplicationContext的自动配置
也就是说,此注释尝试猜测并配置您可能需要的bean
类的自动配置,通常基于类路径应用
您的应用程序和已定义的bean
- 使用@SpringBootConfiguration注释时,会自动启用上下文配置并添加注释,这不会产生任何附加效果…
但我在这里看到的是完全不同的…
没有这个注释,什么都不起作用。。。也就是说,我们没有获得请求的资源
- @组件扫描
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>web.spring.boot.jar</groupId>
<artifactId>web-spring-boot-jar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>web-spring-boot-jar</name>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Entry point