2016-07-07 13 views
0

"/"와 다른 경로를 변경하면 404 오류가 발생합니다. 나는이 컨텍스트 경로에 어떤 문제가 있다는 것을 그것은 나에게 보인다/manager/text와 함께 tomcat7-maven-plugin을 배포 할 때 context가 엉망으로 된 이유

http://localhost:8080/authenticate 404 (Not Found) 

을 얻을 것이다하지만 난 해결하는 방법을 모르는 아래의 pom.xml에

<plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><path>/any_word</path><url>http://localhost:8080/manager/text</url> 

를 사용하는 경우 내 말은, 그것. 나는이 애플리케이션을 로컬 Tomcat에서 실행하도록 관리했으나 확실히 동일한 방식을 프로덕션 환경에 적용 할 수는 없다. Tomcat에서 발견 된 "/"기본값을 삭제했습니다. 그런 다음 "any_word"를 삭제하고 pom.xml에서 "/"를 남겼습니다. 그것은 당신이 상상할 수있는 것처럼 응용 프로그램을 완벽하게 만들지 만 서버 관리자가 나에게 분명하고 고유 한 컨텍스트 경로가 필요하기 때문에 프로덕션의 루트 경로 "/"에 응용 프로그램을 배포 할 수 없습니다.

아래 모든 단계를 추가하고 내 질문에 관련있는 소스를 제공합니다. 덜 중요한 것부터 더 중요한 것까지 내 개인적인 관점에서 명령했다. (나는 pom.xml에 문제가있을 수 있다고 생각하지만 틀릴 수도 있고, 스프링 구성이나 Tomcat Server 속성을 변경해야한다).

브라우저에서 이전에 시작한 "mvn tomcat7 : deploy"대신 "mvn clean install tomcat7 : run-war"를 시작/배포해도 localhost : 8080/calories-tracker가 표시됩니다 Tomcat 서버.

1 - 윈도우

의 명령 프롬프트
C:> mvn tomcat7:deploy 

3 - - 프로필 ("개발")

@Configuration 

@Profile("development") 

@EnableTransactionManagement 

public class DevelopmentConfiguration { 



    @Bean(name = "datasource") 

    public DriverManagerDataSource dataSource() { 



    @Bean(name = "entityManagerFactory") 

    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DriverManagerDataSource dataSource) { 

TomcatManager (http://localhost:8080/manager/html/list)

에서 나는 "/"

이 배포 취소

4 - catalina.properties

spring.profiles.active=development 

5 - Settings.XML의

<servers> 

     <server> 

       <id>tomcat8</id> 

       <username>admin</username> 

       <password>admin</password> 

     </server> 

    </servers> 

6 - WebAppInitializer

public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 

    @Override 

    protected Class<?>[] getRootConfigClasses() { 

     return new Class<?>[]{RootContextConfig.class, DevelopmentConfiguration.class, TestConfiguration.class, 

       AppSecurityConfig.class}; 

    } 



    @Override 

    protected Class<?>[] getServletConfigClasses() { 

     return new Class<?>[] {ServletContextConfig.class}; 

    } 



    @Override 

    protected String[] getServletMappings() { 

     return new String[]{"/"}; 

    } 

} 

- 7의 Web.xml

<web-app> 

    <display-name>Archetype Created Web Application</display-name> 

    <welcome-file-list> 

     <welcome-file>/resources/calories-tracker.html</welcome-file> 

    </welcome-file-list> 

</web-app> 

8의 pom.xml

0,123,516
<build> 

     <finalName>calories-tracker</finalName> 

     <plugins> 

       <plugin> 

        <groupId>org.apache.maven.plugins</groupId> 

        <artifactId>maven-compiler-plugin</artifactId> 

        <version>2.3.2</version> 

        <configuration> 

          <source>${java-version}</source> 

          <target>${java-version}</target> 

        </configuration> 

       </plugin> 





       <plugin> 

        <groupId>org.apache.maven.plugins</groupId> 

        <artifactId>maven-war-plugin</artifactId> 

        <version>2.6</version> 

        <configuration> 

          <failOnMissingWebXml>false</failOnMissingWebXml> 

        </configuration> 

       </plugin> 

       <plugin> 

        <groupId>org.apache.tomcat.maven</groupId> 

        <artifactId>tomcat7-maven-plugin</artifactId> 

        <version>2.2</version> 

        <configuration> 

          <path>/</path> 

          <url>http://localhost:8080/manager/text</url> 

          <server>tomcat8</server> 

          <keystoreFile>${basedir}/other/keystore.jks</keystoreFile> 

          <keystorePass>secret</keystorePass> 

        </configuration> 

       </plugin> 

     </plugins> 

</build> 

*** 몇 분 후에 질문을 추가했습니다. 원래 프로젝트는 https://github.com/jhades/spring-mvc-angularjs-sample-app에서 내릴 수 있습니다. 방금 Tomcat과 Pom으로 위의 내용을 변경했습니다.

+0

프로젝트를 복제하고 tomcat7 플러그인에 '/test'을 넣으십시오. 애플리케이션이 컨텍스트 경로를 테스트하기 위해 배포하지만, 앱이 루트 경로에서 해당 경로를 찾을 것으로 예상하기 때문에 CSS와 이미지가 엉망입니다. – Apostolos

+0

Apostolos, 어떻게 해결할 수 있습니까? 애플리케이션에서 어디에서 변경해야합니까? AngularJS에 매우 제한적입니다. AngularJS 구성에서 변경해야 할 부분입니까? –

+0

내가 그것을 확인하자 그리고 정확하게 경로를 설정하는 방법을 찾으면, 내 대답을 게시 할게 :) – Apostolos

답변

1

컨트롤러에 $ location을 추가해야합니다.

angular.module('common', ['ngMessages']) 
    .controller('BaseFormCtrl', ['$scope', '$http', '$location', function ($scope, $http, $location) { 

     var fieldWithFocus; 

     $scope.path = $location.absUrl().split('/')[3]; 

     $scope.vm = { 
      submitted: false, 
      errorMessages: [] 
     }; 

범위 변수에 컨텍스트 경로를 저장하면 지정한 컨트롤러 컨텍스트에서 사용할 수 있습니다. 어쩌면 가장 깔끔한 방법은 아니지만 작동합니다!

편집 : 먼저 당신은 당신이 행동

<link rel="stylesheet" type="text/css" href="/{{path}}/resources/bower_components/pure/pure.css"> 
<link rel="stylesheet" type="text/css" href="/{{path}}/resources/bower_components/pure/grids-responsive.css"> 
<link rel="stylesheet" type="text/css" href="/{{path}}/resources/public/css/pure-theme.css"> 
<link rel="stylesheet" type="text/css" href="/{{path}}/resources//public/css/calories-tracker.css"> 

에서 그것을보고 싶어하면, 다음

<script type="text/javascript" data-main="./js/run-loggin-app" 
     src="../bower_components/requirejs/require.js"></script> 

을 필요로의 로그인 페이지에 다음 태그를 변경해야하지만이 몇 밀리 초를 취할 것 로드하려면 어떤 각도에서도 CSS가없는 페이지가 인스턴스에 표시됩니다.

당신은 링크를 상대 경로로 변경하는 차이점을 볼 수 있습니다.

<link rel="stylesheet" type="text/css" href="../bower_components/pure/pure.css"> 
<link rel="stylesheet" type="text/css" href="../bower_components/pure/grids-responsive.css"> 
<link rel="stylesheet" type="text/css" href="../public/css/pure-theme.css"> 
<link rel="stylesheet" type="text/css" href="../public/css/calories-tracker.css"> 

링크를 먼저 변경하고 POST/GET 끝점을 변경 한 다음 스타일 링크를 어떻게 처리할지 결정할 수 있습니다.

+0

Apostolos, 나는 당신에게 아주 좋은 속임수를 제공하는 것을 볼 수있다. 그러나 나는 그것을 구현하는 방법을 조금 혼란스럽게 생각한다. Hello World를 가리킬 수 있다면 많이 물어볼 것인가 아니면 git에서 응용 프로그램을 다운로드하고 정확히 내가 바꿔야 할 곳을 지적 할 것인가? 솔직히, initialy 나는 서버에 배포하는 방법에 불과하다고 생각했지만 AngularJs에서는 컨텍스트 경로를 유연하게 만들기 위해 특정 해결 방법을 코딩하는 것이 정상적인 것 같습니다. 내가 Angularjs에서 매우 beginer이기 때문에 모든 팁은 높이 평가 될 것입니다. –