Spring Boot应用程序未启动。没有错误,但正在停止服务[Tomcat]

时间:2019-06-25 17:17:26

标签: spring-boot transactions spring-transactions

我无法在嵌入式Tomcat上运行Spring Boot应用程序。在添加注释@Transactional

之前,它工作正常

我已经将Spring Boot版本从2.1.3.RELEASE更改为2.1.6.RELEASE,但是没有用。

      .   ____          _            __ _ _  /\\ / ___'_ __ _ _(_)_ __  __
    _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )   '  |____| .__|_| |_|_| |_\__, | / / / / 
    =========|_|==============|___/=/_/_/_/  
:: Spring Boot ::        (v2.1.6.RELEASE)

六月 26, 2019 12:52:18 上午 org.apache.catalina.core.StandardService startInternal 信息: Starting service [Tomcat] 
六月 26, 2019 12:52:18 上午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet engine: [Apache Tomcat/9.0.21] 
六月 26, 2019 12:52:19 上午 org.apache.jasper.servlet.TldScanner scanJars 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
六月 26, 2019 12:52:19 上午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring embedded WebApplicationContext 
六月 26, 2019 12:52:20 上午 org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [   name: default   ...] 
六月 26, 2019 12:52:21 上午 org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.3.10.Final} 
六月 26, 2019 12:52:21 上午 org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found 
六月 26, 2019 12:52:21 上午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {5.0.4.Final} 
六月 26, 2019 12:52:21 上午 org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect 
六月 26, 2019 12:52:22 上午 org.apache.catalina.core.StandardService stopInternal 信息: Stopping service [Tomcat] [INFO]
[INFO] BUILD SUCCESS [INFO]
[INFO] Total time: 15.774 s [INFO] Finished at: 2019-06-26T00:52:22+08:00 [INFO] Final Memory: 48M/363M [INFO]

Process finished with exit code 0

主类

@SpringBootApplication
@MapperScan("com.jonathan.dao")
@EnableTransactionManagement
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) throws  Exception{
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
}

服务等级

@Service
public class TeacherServices {

    @Resource
    private TeacherMapper teacherMapper;
    @Resource
    private RoleMapper roleMapper;

?//The Application can't starting when I add this annotation?
    @Transactional(rollbackFor = Exception.class) 
    public void insertTeacherAndRole(Teacher teacher,String roleName)throws Exception{
        teacherMapper.insertTeacher(teacher);
        int teacherId = teacherMapper.findIdByAdminName(teacher.getName());
        int roleId = roleMapper.getRoleIdByRoleName(roleName);
        teacherMapper.insertTeacherAndRole(teacherId,roleId);
    }

}

Pom.xml

<properties>
        <file.encoding>UTF-8</file.encoding>
        <!--<spring.version>5.1.5.RELEASE</spring.version>-->
        <mysql.version>8.0.13</mysql.version>
        <druid.version>1.1.16</druid.version>
        <mybatis.version>2.0.1</mybatis.version>
        <javax.servlet.version>4.0.1</javax.servlet.version>
        <jstl.version>1.2</jstl.version>
        <spring-boot.version>2.1.3.RELEASE</spring-boot.version>
        <embed.version>9.0.12</embed.version>
        <jstl.version>1.2</jstl.version>
        <jspapi.version>2.0</jspapi.version>
        <json.version>2.3</json.version>
        <fileupload.version>1.3.3</fileupload.version>
        <lang3.version>3.9</lang3.version>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${lang3.version}</version>
        </dependency>

        <!-- commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>${fileupload.version}</version>
        </dependency>

        <!--springboot-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <!--依赖的数据库驱动类库-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!--依赖的连接池类库-->
        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>

        <!--依赖的Web类库-->
        <!--JSTL for JSP-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>

        <!--compile JSP-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>${embed.version}</version>
            <scope>compile</scope>
        </dependency>

        <!--运维组件-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring-boot.version}</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Tomcat embedded container-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--集成Mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <!-- 分布插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.1</version>
        </dependency>
        <!-- Spring Boot集成 pagehelper-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.10</version>
        </dependency>
        <!-- 为idea 生成配置属性信息 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <!--保证Spring boot热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>

        <!-- json -->
        <dependency>
            <groupId>net.minidev</groupId>
            <artifactId>json-smart</artifactId>
            <version>${json.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-web -->

        <!--shiro相关组件-->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring-boot-starter</artifactId>
            <version>1.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!--配置运行插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <!--增加jvm参数-->
                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.7</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>

我花了很多时间,但是还没有解决,请帮帮我!THX!

0 个答案:

没有答案