当我在内置服务器或其他tomcat服务器上运行此应用程序时,它显示以下错误消息。我正在使用jdk8,STS V-3.9.7。有人可以帮我解决吗
具有以下内容的简单Springboot应用程序:
用于视图映射的application.properties文件
spring.mvc.view.prefix=/WEB-INF/jspViews/
spring.mvc.view.suffix=.jsp
Run Code Online (Sandbox Code Playgroud)
index.jsp
<body>
<h3>Application is working</h3>
</body>
Run Code Online (Sandbox Code Playgroud)
控制器类
@Controller
public class AppController {
@RequestMapping("/")
public String indexPage() {
return "index";
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml文件
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ehospitalsso</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins> …Run Code Online (Sandbox Code Playgroud) 根据Spring Boot的文档,可以通过设置会话超时来配置
server.servlet.session.timeout= 300s
Run Code Online (Sandbox Code Playgroud)
在application.properties文件中。在这篇文章和Spring Boot文档中也是如此。但不幸的是,这对我不起作用。
还有其他配置可以达到预期效果吗?
我将Spring Security集成到现有的Spring Boot项目中(版本:1.5.3.RELEASE).
在集成之前,我们通过扩展HandlerInterceptorAdapater的preHandle方法通过getRequestURI从请求中获取重定向信息.
请求URI正确指向其路径(例如:/ admin/login).
集成后,请求URI指向jsp的完整路径.
此外,我们已经向ConfigurableApplicationContext注册了一个ContextUtil类,以进行进一步的URI检查.在这个类中,我们获取这样的请求:
public HttpServletRequest getCurrentRequest()
{
final ServletRequestAttributes servletRequestAttributes =
(ServletRequestAttributes)
RequestContextHolder.currentRequestAttributes();
return servletRequestAttributes.getRequest();
}
Run Code Online (Sandbox Code Playgroud)
但URI也是其"物理路径"下的 /WEB-INF/
例如:GET请求指向/WEB-INF/pages/admin/admin_login.jsp:
我的WebSecurityConfig班级是:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http) throws Exception
{
//jeden Aufruf akzeptieren. Authorisierung und
Authentifizierung von Spring Security wird nicht genutzt
http.authorizeRequests().antMatchers("/").permitAll();
}
@Override
public void configure(WebSecurity web) throws Exception
{
web.ignoring().antMatchers("/resources/**", "/css/**", "/js/**",
"/img/**", "resources/*", "/WEB-INF/**").and().debug(true);
}
}
Run Code Online (Sandbox Code Playgroud)
相关applicationContext.xml部分:
<mvc:default-servlet-handler/>
<mvc:annotation-driven/> …Run Code Online (Sandbox Code Playgroud) 将Spring Boot 1.5更新到2.1.5
尝试执行操作repository.save(entity)时,会出现以下错误:
Caused by: com.impossibl.postgres.jdbc.PGSQLSimpleException: cannot execute UPDATE in a read-only transaction
Run Code Online (Sandbox Code Playgroud)
我们使用org.springframework.data.repositoryCrudRepository接口执行操作。
1)@Transactional(readOnly = false),如我所知,将只读模式设置为false只能作为对子层的提示,我如何检查和更改其他层?
@Service
public class ServiceImpl
private final Repository repository;
@Autowired
public ServiceImpl(Repository repository) {
this.repository = repository;
}
@Transactional(readOnly = false)
public void operation(Entity entity){
repository.save(entity);
}
Run Code Online (Sandbox Code Playgroud)
和存储库是
public interface Repository extends CrudRepository<Entity, UUID>{
@Query("select e from Entity e where lower(u.name) = lower(?1)")
Entity findByName(String name);
}
Run Code Online (Sandbox Code Playgroud)
build.gradle
------------
`dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.5.RELEASE")
}
`
```runtime("org.springframework.boot:spring-boot-properties-migrator")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-jersey")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jetty") …Run Code Online (Sandbox Code Playgroud) Now i am doing project with Spring Boot. I wanted to show error message when I fail to login. When I did Maven project I did it easily with BindingResult. I followed several instruction to complete the task what I wanted to do. But I couldn't get any proper solution. I need a proper solution in simplest way.
Here my Controller class
@RequestMapping(value = "/loginCheck", method = RequestMethod.POST)
public String checkLogin(@RequestParam String roll, @RequestParam String pass) {
if (studentService.existsByRollAndPass(roll, pass)) …Run Code Online (Sandbox Code Playgroud) 在我的 Spring Boot 项目中,我有一个html包含学生列表的页面。在那个页面中,我有两个选项Edit,Delete每个学生都有。我想在单击 时显示每个学生信息的模式值Edit。但我无法做到这一点。另一个奇怪的事情是每次我点击 any 时Edit,表单只填充列表的第一个成员。也许我将不得不添加一些JavaScript代码或其他东西。这是学生列表页面的截图
] 1
我的html文件是
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:sf="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Student List</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<script th:if="${existRoll != null}">
$(function () {
$('#myModal').modal('show');
});
</script>
<body>
<div class="container">
<h1 style="text-align:center;">Students List</h1>
<table class="table table-striped">
<tr>
<th>Id</th>
<th>Roll</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Setting</th>
</tr>
<tr th:each="student : ${studentList}"> …Run Code Online (Sandbox Code Playgroud) spring-boot ×4
java ×3
html ×2
spring ×2
thymeleaf ×2
hibernate ×1
hikaricp ×1
javascript ×1
jsp ×1
postgresql ×1
server ×1
session ×1
spring-mvc ×1
tomcat ×1
uri ×1