2017-03-16 5 views
0

나는 Spring Initializer, 임베디드 Tomcat, Thymeleaf 템플릿 엔진을 사용하여 Spring Boot 웹 애플리케이션을 생성했다. 사용 된 기술 : Spring Boot 1.4.2.RELEASE, Spring 4.3.4. RELEASE, Thymeleaf 2.1.5.RELEASE, 톰캣 삽입 8.5.6, 메이븐 3, 자바 8. 나는SpringBoot : pom.xml 파일의 메인 클래스 정의하기

이 pom.xml 파일을 가지고 있고이 명령을

mvn clean package -DskipTests -Dspring.profiles.active=pebloc,war -DAPPKEY=pebloc 

치어를 사용하여 전쟁을 생성 .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.bookcloud</groupId> 
    <artifactId>bookcloud</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <name>bookcloud</name> 
    <description>Book Cloud </description> 

    <profiles> 
     <profile> 
      <id>jar</id> 
      <properties> 
       <spring.boot.mainclass>com.bookcloud.iot.BookCloudApplication</spring.boot.mainclass> 
      </properties> 
     </profile> 
     <profile> 
      <id>war</id> 
      <properties> 
      <spring.boot.mainclass>com.bookcloud.iot.BookCloudApplicationWar</spring.boot.mainclass> 
      </properties> 
     </profile> 
    </profiles> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.2.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <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-aop</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-jdbc</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-mail</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>it.ozimov</groupId> 
      <artifactId>spring-boot-email-core</artifactId> 
      <version>0.5.1</version> 
     </dependency> 
     <dependency> 
      <groupId>it.ozimov</groupId> 
      <artifactId>spring-boot-thymeleaf-email</artifactId> 
      <version>0.5.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-security</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-thymeleaf</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-batch</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
      </dependency> 

     <!-- https://mvnrepository.com/artifact/com.icegreen/greenmail --> 
     <dependency> 
      <groupId>com.icegreen</groupId> 
      <artifactId>greenmail</artifactId> 
      <version>1.5.3</version> 
      <optional>true</optional> 
      <scope>test</scope> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpclient</artifactId> 
     </dependency>  

     <!-- hot swapping, disable cache for template, enable live reload --> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-devtools</artifactId> 
      <optional>true</optional> 
     </dependency> 


     <dependency> 
      <groupId>org.hsqldb</groupId> 
      <artifactId>hsqldb</artifactId> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <scope>runtime</scope> 
     </dependency> 

    </dependencies> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.springframework.cloud</groupId> 
       <artifactId>spring-cloud-dependencies</artifactId> 
       <version>Camden.SR5</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId>    
       <executions> 
        <execution> 
         <goals> 
          <goal>repackage</goal> 
         </goals> 
         <configuration> 
          <mainClass>${spring.boot.mainclass}</mainClass> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 


</project> 
,

하지만 난이 오류가 계속있어 :

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) on project bookcloud: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.bookcloud.iot.BookCloudApplication, com.bookcloud.iot.BookCloudApplicationWar] -> [Help 1] 

BookCloudApplication.java

@Profile("!war") 
@SpringBootApplication 
@Import({SecurityConfig.class ,PersistenceConfig.class, ServiceConfig.class}) 
public class BookCloudApplication { 

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

BookCloudApplicationWar.java

@Profile("war") 
@Import({SecurityConfig.class ,PersistenceConfig.class}) 
@SpringBootApplication 
public class BookCloudApplicationWar extends SpringBootServletInitializer { 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(BookCloudApplicationWar.class); 
    } 

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

} 
+0

주 수업을 포함하는 질문을 편집하십시오. –

답변

2

Maven 프로필 Spring 정보는 관련이 없다.

당신은 두 Maven 프로파일이 : 항아리, 전쟁을

당신에게 중 하나를 사용 :

mvn clean package -Pjar 

또는

mvn clean package -Pwar 

이슈를 구축하는 동안 당신이 점점 오류가 pom이 필요하기 때문에 :

<start-class>your.app.entry.point.Main</start-class> 

속성 요소 안에 있습니다.

Maven 프로필에 관계없이 하나의 시작 클래스 만있는 것이 좋습니다. 같은

뭔가 :

의 pom.xml :

... 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.asimio.cloud</groupId> 
<artifactId>zuul-server</artifactId> 
<version>0-SNAPSHOT</version> 
<packaging>${packaging.type}</packaging> 
... 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
    <start-class>your.app.entry.point.Main</start-class> 
    <packaging.type>jar</packaging.type> 
... 
<profiles> 
    <profile> 
    <id>war</id> 
    <properties> 
     <packaging.type>war</packaging.type> 
    </properties> 
    <dependencies> 
     <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-tomcat</artifactId> 
     <scope>provided</scope> 
     </dependency> 
    </dependencies> 
... 
    </profile> 
</profiles> 
... 

Main.java : Spring 프로파일

package your.app.entry.point; 
... 
@SpringBootApplication 
@Import({SecurityConfig.class ,PersistenceConfig.class, ServiceConfig.class}) 
public class App extends SpringBootServletInitializer { 

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

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

필요가 없습니다.이 유물은 이제 하나 Maven 프로필을 사용하여 구축 할 수 있으며, 사용 중 하나를 실행합니다 : 항아리로이 유물을 구축 할 때

java -jar ..... 

또는 서블릿 컨테이너에 배포 WAR 파일로

구축 할 때 -Pwar Maven 프로필을 사용합니다.

1

메이븐 프로파일과 봄 프로파일은 두 개의 서로 다른 개념입니다.

정확도가 일치하는 값으로 spring.boot.mainclass 속성을 설정하려면 war 프로필을 사용하여 Maven을 실행해야합니다.

Maven 프로파일을 활성화하려면 명령 행에 -Pwar을 추가하십시오.

mvn clean package -DskipTests -Pwar -Dspring.profiles.active=pebloc,war -DAPPKEY=pebloc