2017-05-03 2 views
0

간단한 스프링 부트 MVC 어플리케이션을 개발 중입니다. 이전에는 Spring + Hibernate (즉, servlet.xml 등)만으로 작업 했었고 Spring Boot를 사용하기 위해 프로젝트를 다시 작성하려고합니다. 비록 내가 봄 부팅을 .jsp 파일을 찾지 못하는 문제를 해결할 수 없다는 많은 답변을 읽었으므로 - 화이트리스트 오류 페이지를 표시합니다.
많은 답변은 tomcat-embed-jasperjstlpom.xml에 포함하고 있지만 이미 사용하고 있습니다. 저는 IntelliJ IDEA 17 Ultimate, Tomcat 8.5.13, Spring과 Spring Boot의 최신 버전을 사용하고 있습니다.스프링 부트 jsp 파일을 찾을 수 없습니다.

프로젝트 구조 :
enter image description here

의 pom.xml :

<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> 
<artifactId>spring-invoice</artifactId> 
<groupId>spring-invoice</groupId> 
<version>1.0.0</version> 
<packaging>war</packaging> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.3.RELEASE</version> 
</parent> 

<properties> 
    <springframework.version>4.3.8.RELEASE</springframework.version> 
    <hibernate.version>5.2.9.Final</hibernate.version> 
    <mysql.connector.version>5.1.41</mysql.connector.version> 
    <hibernatevalidator.version>5.4.1.Final</hibernatevalidator.version> 
    <start-class>com.invoices.Application</start-class> 
</properties> 

<dependencies> 

    <!-- Spring boot --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

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

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

    <dependency> 
     <groupId>org.apache.tomcat.embed</groupId> 
     <artifactId>tomcat-embed-jasper</artifactId> 
     <scope>provided</scope> 
    </dependency> 

    <!-- Spring --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-tx</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-beans</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <!-- Hibernate --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>${hibernate.version}</version> 
    </dependency> 

    <!-- Hibernate validator --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>${hibernatevalidator.version}</version> 
    </dependency> 

    <!-- MySQL --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>${mysql.connector.version}</version> 
    </dependency> 

    <!-- C3PO --> 
    <dependency> 
     <groupId>com.mchange</groupId> 
     <artifactId>c3p0</artifactId> 
     <version>0.9.5.2</version> 
    </dependency> 

    <!-- Servlet + JSP + JSTL --> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet.jsp</groupId> 
     <artifactId>javax.servlet.jsp-api</artifactId> 
     <version>2.3.1</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
    </dependency> 

</dependencies> 

<build> 

    <finalName>spring-invoice</finalName> 

    <plugins> 

     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 

     <!-- The Compiler Plugin is used to compile the sources of project --> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.6.0</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 

     <!-- Builds a Web Application Archive (WAR) file from the project output and its dependencies. --> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>3.0.0</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 

    </plugins> 

</build> 

</project> 

application.properties 파일

# Database 
spring.datasource.url=jdbc:mysql://localhost:3306/fakturowanie 
spring.datasource.username=root 
spring.datasource.password=1234 
spring.datasource.driver-class-name=com.mysql.jdbc.Driver 
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect 

# Hibernate 
spring.jpa.hibernate.ddl-auto=update 
spring.jpa.show-sql=true 

entitymanager.packagesToScan=com.invoices 
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy 

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

Application 클래스

@SpringBootApplication 
public class Application extends SpringBootServletInitializer 
{ 
    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) 
    { 
     return application.sources(Application.class); 
    } 

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

내 JSP 파일

<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
 
<html lang="pl-PL"> 
 
<head> 
 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
 
    <title>Zarządzaj kontrahentami</title> 
 
</head> 
 
<body> 
 

 
    <div id="wrapper"> 
 
     <div id="header"> 
 
      <h2>Zarządzaj kontrahentami</h2> 
 
     </div> 
 
    </div> 
 

 
    <div> 
 
     <div> 
 
      <!-- put new button: Add Customer --> 
 
      <input type="button" value="Dodaj nowego kontrahenta" 
 
        onclick="window.location.href='addCustomer'; return false;" 
 
        class="add-button"/> 
 

 
      <table> 
 
       <tr> 
 
        <th>Alias</th> 
 
        <th>Nazwisko</th> 
 
        <th>Imię</th> 
 
        <th>Nazwa firmy</th> 
 
        <th>NIP/PESEL</th> 
 
        <th>Ulica i nr mieszkania</th> 
 
        <th>Kod pocztowy</th> 
 
        <th>Miejscowość</th> 
 
        <th>Sposób zapłaty</th> 
 
        <th>Uwzględnij numer faktury</th> 
 
       </tr> 
 

 
       <c:forEach var="tempCustomer" items="${allCustomers}"> 
 

 
        <c:url var="updateLink" value="/customers/updateCustomer"> 
 
         <c:param name="customerID" value="${tempCustomer.id}"/> 
 
        </c:url> 
 

 
        <c:url var="deleteLink" value="/customers/deleteCustomer"> 
 
         <c:param name="customerID" value="${tempCustomer.id}"/> 
 
        </c:url> 
 

 
        <tr> 
 
         <td>${tempCustomer.alias}</td> 
 
         <td>${tempCustomer.lastName}</td> 
 
         <td>${tempCustomer.firstName}</td> 
 
         <td>${tempCustomer.companyName}</td> 
 
         <td>${tempCustomer.taxIdentifier}</td> 
 
         <td>${tempCustomer.postalCode}</td> 
 
         <td>${tempCustomer.city}</td> 
 
         <td>${tempCustomer.paymentMethod}</td> 
 
         <td>${tempCustomer.includeInCount}</td> 
 

 
         <td> 
 
          <!-- display the update and delete link --> 
 
          <a href="${updateLink}">Edytuj</a> 
 
          | 
 
          <a href="${deleteLink}" onclick="if (!(confirm(
 
           'Czy na pewno usunąć tego kontrahenta?'))) return false">Usuń</a> 
 
         </td> 
 

 
        </tr> 
 

 
       </c:forEach> 
 

 
      </table> 
 

 
     </div> 
 
    </div> 
 

 
</body> 
 
</html>

중 하나 그리고 당신은 봄 부팅을 사용하지만 치어 충돌 종속성이 수수께끼를

@Controller 
@RequestMapping("/customers") 
public class CustomersController implements IUtilities<Customer> 
{ 
    @Autowired 
    private ICustomerDAO customerDAO; 

    @GetMapping("/manageCustomers") 
    public String manageCustomers(Model model) 
    { 
     List<Customer> allCustomers = convertIterableToCollection(customerDAO.findAll()); 
     model.addAttribute("allCustomers", allCustomers); 
     return "manage-customers"; 
    } 

    @GetMapping("/addCustomer") 
    public String showFormForAdd(Model model) 
    { 
     // create model attribute to bind form data 
     Customer theCustomer = new Customer(); 

     model.addAttribute("customerToEdit", theCustomer); 

     return "customer-form"; 
    } 

    @GetMapping("/updateCustomer") 
    public String showFormForUpdate(@RequestParam("customerID") int customerId, Model model) 
    { 
     // get the customer from service 
     Customer theCustomer = customerDAO.findOne(customerId); 
     model.addAttribute("customerToEdit", theCustomer); 

     //redirect to update form 
     return "customer-form"; 
    } 

    @GetMapping("/deleteCustomer") 
    public String deleteCustomer(@RequestParam("customerID") int customerId) 
    { 
     //delete the customer 
     customerDAO.delete(customerId); 

     return "redirect:/customers/manageCustomers"; 
    } 

    @PostMapping("/saveCustomer") 
    public String saveCustomer(@ModelAttribute("customerToEdit") Customer customer) { 
     //save the customer using our service 
     customerDAO.save(customer); 

     return "redirect:/customers/manageCustomers"; 
    } 

    @Override 
    public List<Customer> convertIterableToCollection(Iterable<Customer> iterable) { 
     List<Customer> list = new ArrayList<>(); 
     iterable.forEach(list::add); 
     return list; 
    } 
} 
+0

viewResolver에 대한 bean 추가 위치 –

+0

내 프로젝트에서 viewResolver와 비슷한 점이 없다고 생각합니다. xml 파일이나 구성 클래스도 없습니다. – Colonder

+0

기본 대답은 기본 Maven 프로젝트 레이아웃을 사용하고 있지 않습니다. –

답변

2

그것의 컨트롤러. 처음에는 pom.xml을 청소하십시오. 또한 당신의 치어에 최소한 대신 기본 compile 범위의 spring-boot-starter-tomcatprovided을 의미합니다합니다 (JSP Samples pom.xml에서 수행되고 있는지 고려해야한다.

을 마지막으로 당신이 그 같이있는 maven-compilemaven-war 플러그인이 필요하지 않습니다 이미 부모로부터 상속.

<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> 
<artifactId>spring-invoice</artifactId> 
<groupId>spring-invoice</groupId> 
<version>1.0.0</version> 
<packaging>war</packaging> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.3.RELEASE</version> 
</parent> 

<properties> 
    <hibernate.version>5.2.9.Final</hibernate.version> 
    <start-class>com.invoices.Application</start-class> 
</properties> 

<dependencies> 

    <!-- Spring boot --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

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

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

    <dependency> 
     <groupId>org.apache.tomcat.embed</groupId> 
     <artifactId>tomcat-embed-jasper</artifactId> 
     <scope>provided</scope> 
    </dependency> 

    <!-- MySQL --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
    </dependency> 

    <!-- C3PO --> 
    <dependency> 
     <groupId>com.mchange</groupId> 
     <artifactId>c3p0</artifactId> 
     <version>0.9.5.2</version> 
    </dependency> 

    <!-- Servlet + JSP + JSTL --> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
    </dependency> 

</dependencies> 

<build> 

    <finalName>spring-invoice</finalName> 

    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 

</build> 

</project> 

는 또한 JSP를 함께 봄 부팅을 사용하고있을 경우 계정 the limitations 고려.

실제 문제가 프로젝트 구조 그러나

, 당신이저기서된다 g Maven은 자바 소스에 대해 src/main/java 디렉토리가 있어야하며 모든 웹 관련 내용은 web 대신 src/main/webapp이어야하고 Java 이외의 관련 자원은 src/main/resources이어야합니다. 이 기본 구조가 없기 때문에 파일은 올바른 위치에 복사되지 않습니다 (실제로 무시됩니다).

+0

나는 이전 버전의 프로젝트에서'pom.xml'을 상속했다 - 나는 그것을 정리하고 그것이 작동하는지 확인하려고 노력할 것이다. – Colonder

+0

나의 수정 된 답변을 보라 (실제 문제는 프로젝트 구조이다). 아니 귀하의 pom 청소 더 이상 문제 (및 유지 보수)를 방지합니다. –

+0

그것이 내가 정직하다고 생각한 것이지만, 여전히 IntelliJ가 새로운 프로젝트를 만들 때 내게주는 것입니다. 그렇다면 Spring Boot와 Maven으로 작업 할 때마다 수동으로 프로젝트 구조를 다시 만들어야한다는 의미입니까? – Colonder

관련 문제