小编Dai*_*mon的帖子

Spring启动hibernate没有事务正在进行中

我正在使用弹簧靴,它完美地让我成为实体经理.我决定从实体管理器测试获取会话工厂并将其用作示例.但我得到了下一个问题:javax.persistence.TransactionRequiredException: no transaction is in progress

性能

spring.datasource.url= jdbc:postgresql://localhost:5432/ring
spring.datasource.username=postgres
spring.datasource.password=root

spring.jpa.show-sql = false
spring.jpa.properties.hibernate.format_sql=false

#Note: The last two properties on the code snippet above were added to suppress an annoying exception
# that occurs when JPA (Hibernate) tries to verify PostgreSQL CLOB feature.
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false

spring.jpa.properties.hibernate.current_session_context_class = org.springframework.orm.hibernate5.SpringSessionContext
Run Code Online (Sandbox Code Playgroud)

服务类

package kz.training.springrest.service;

import kz.training.springrest.entity.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;

@Service
public class UserService {

    @PersistenceContext
    private …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-boot

2
推荐指数
1
解决办法
5438
查看次数

Spring boot在多模块项目中找不到jsp

我正在使用 spring boot,我决定只是为了将我的项目分成模块。我有 4 个模块,Web、服务、存储库、域。除了JSP,一切正常,spring 找不到这些页面。但是当我没有将我的项目拆分为模块时,它就起作用了。我没有改变配置。

这是我的网络模块结构

在此处输入图片说明

Runner 位于 web 模块中,这里是:

@SpringBootApplication(scanBasePackages = "kz.epam.javalab.daimoncool")
public class WebApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的 application.properties:

spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.physical_naming_strategy=com.vladmihalcea.hibernate.type.util.CamelCaseToSnakeCaseNamingStrategy

spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
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>kz.epam.javalab.daimoncool</groupId>
    <artifactId>newsmanagementparent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>newsmanagementparent</name>
    <packaging>pom</packaging>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent …
Run Code Online (Sandbox Code Playgroud)

java spring jsp http-status-code-404 spring-boot

0
推荐指数
1
解决办法
967
查看次数

标签 统计

java ×2

spring ×2

spring-boot ×2

hibernate ×1

http-status-code-404 ×1

jpa ×1

jsp ×1