springboot fight the war package summary

Outline

  The first time I played with the tool maven war package, a variety of problems, to be a problem for next time viewing record

maven

  I started using maven is springboot default under .m2, only to find no mvn package instructions. Simply himself re-install a maven, go to the official website to download, I installed the 3.5.2 version. Maven repository because default is abroad, we need to change to address the country's image, facilitate the establishment of a local warehouse, then change setting.xml file, add a new label in the <mirrors> tag, after the completion configure their own environment variables, the following figure lz own computer is configured, according to their installation directory, after the completion of testing under maven -version

    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>

Environment Variables

 

 

 

 

 

 

To download the specified local address of the warehouse, so adding a local address

<localRepository>D:\maven\repository</localRepository>

IDEA configuration maven

  In addition, IDEA also need to change the default maven address, home directory select local maven, file select local maven profile, local repository select the local repository path

Modify pom.xml

Reload maven-> reimport, the local repository download time is slower, slowly wait for it. After the local repository download is complete, you must modify packaged form, added in pom.xml

<packaging>war</packaging>

Because springboot incorporates a tomcat container labeled as war if the package is placed in an external server tomcat, there will be conflict, so the removal of internal tomcat container, add in pom.xml

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

还需要添加servlet-api依赖

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

如果不想用maven打包出来的war名称,还得添加自己自定义的名称

<finalName>seasgame</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <encoding>${project.build.sourceEncoding}</encoding>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <testFailureIgnore>true</testFailureIgnore>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

pom.xml修改到这里,我们开始进行打包,在pom.xml那层目录,执行 mvn clean package

启动类修改

public class SpringBootStartApplication extends SpringBootServletInitializer
{
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
    {
        // 注意这里要指向原先用main方法执行的SeasgameApplication启动类
        return builder.sources(SeasgameApplication.class);

    }
}

问题汇总

因为移除了tomcat,所以跟tomcat依赖相关的得更改。

ERROR: expected START_TAG or END_TAG not TEXT

这是因为pom.xml的文件内,有不合法的语法,也可以看提示哪一行出的问题,建议处理方法将idea的检验级别拉高,有问题就会一下子报红。将标签内容补全,重新在进行打包

ERROR:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

这是因为我们需要之指定一个符合配置的JDK环境,这个问题一般是因为装有多个版本的jdk引发的,idea的maven配置Runner,需要配置哪个版本,最好都一致。

ERROR:Unsupported major.minor version 52.0

版本信息不一致,低版本编译高版本出的问题,springboot我建议用tomcat 8 以上和jdk8以上,因为tomcat7太过老旧了,可能会出现各种不兼容的问题,升级后一般能解决很多问题。

ERROR: Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5

这是被某个程序占用了,我们重新启动下idea,甚至还无法解决可以重启。

在打包的时候出现这几个问题,一 一解决后要部署到服务器。因为服务器还是用jdk7和tomcat7。。各种版本不兼容,很头疼。只能自己在装一个jdk8 和tomcat8,在tomcat8内指定jdk版本运行。

在tomcat8的bin下修改 setclasspath.sh 在第一行添加

export JAVA_HOME=/usr/local/jdk1.8.0_172/
export JAVA_HOME=/usr/local/jdk1.8.0_172/jre

如何还不行,在catalina.sh内也添加上。因为有多个版本tomcat所以端口号会冲突,修改server里的端口号。。可参考这篇文件

https://blog.csdn.net/Jay_1989/article/details/52870760

好了,启动tomcat8,发现

ERROR:Field xxxService in 某个类 required a single bean, but 3 were found

这是因为我在内部有个工程类

private EntityManager entityManager;

找不到这个bean,将注解弄掉。顺利跑起来了,第一次打war包花了一下午的时间,终于成功跑起来,访问127.0.0.1:端口号

 

Guess you like

Origin www.cnblogs.com/dslx/p/11465842.html
Recommended