在html
文件中,有一个图像:
<div class="login-branding">
<a href="index.html"><img src="../static/images/logo.png" alt="Clevex" title="Clevex"></a>
</div>
在http://localhost:8090/login的地址,我看到控制台,看到:
但是当应用程序启动时,如果我去
http://localhost:8090/images/logo.png
此网址,我可以在chrome
浏览器的控制台上看到图像而没有任何错误或警告。
这是我的安全配置:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAuthenticationProvider customAuthenticationProvider;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable();
String[] resources = new String[]{
"/",
"/home",
"/pictureCheckCode",
"/include/**",
"/css/**",
"/icons/**",
"/images/**",
"/js/**",
"/resources/**",
"/layer/**",
"/static/**",
"/js/**",
"/img/**",
"/webjars/**"
};
http
.authorizeRequests()
.antMatchers(resources).permitAll()
我还添加了@EnableAutoConfiguration
,但是它什么也没做。并给出了错误。
我不想使用addResourceHandlers
,因为它是Spring Boot,它应该进行自动配置。
目录如下:
src
-main
-resources
--static
---images
----logo.png
这是应用程序启动的方式:
@SpringBootApplication
public class InternalApplication {
public static void main(String[] args) {
SpringApplication.run(InternalApplication.class, args);
}
}
任何建议将不胜感激。
答案 0 :(得分:1)
static
目录中的所有内容都在Web应用程序的根目录中提供。因此/static/images/logo.png
由Spring Boot的/images/logo.png
提供服务。
所以替换:
src="../static/images/logo.png"
具有:
src="/images/logo.png"
答案 1 :(得分:0)
这有效:
https://stackoverflow.com/a/56196207/11369236
我改变了
<a href="index.html"><img src="../static/images/logo.png" alt="Clevex" title="Clevex"></a>
到
<a href="index.html"><img src="/images/logo.png" alt="Clevex" title="Clevex"></a>
由于Intellij Idea
,我感到困惑。
在HTML
代码中,如果我单击../static/images/logo.png
,它可以转到图像。
但是当我在HTML代码中单击/images/logo.png
时,它却没有显示,sonar
也为此发出了警告。