简体   繁体   English

为什么用/ manager / text部署tomcat7-maven-plugin弄乱了上下文

[英]why deploy tomcat7-maven-plugin with /manager/text messed up the context

If I change the path to anything different from "/" I get 404 error. 如果我将路径更改为不同于“ /”的任何内容,则会收到404错误。 I mean, if use 我的意思是,如果使用

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

in the below pom.xml then I will get 在下面的pom.xml中,我将得到

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

It seems to me that there is certain issue with context path but I don't know how to fix it. 在我看来,上下文路径存在某些问题,但我不知道如何解决。 I managed to make the application run in my local Tomcat but certainly I can't apply same approach in production. 我设法使该应用程序在本地Tomcat中运行,但是当然我不能在生产中应用相同的方法。 I deleted the "/" default found in Tomcat. 我删除了在Tomcat中找到的默认“ /”。 Then, I took away "any_word" and just left "/" in pom.xml. 然后,我拿走了“ any_word”,并在pom.xml中仅保留了“ /”。 It makes the application run perfectly but, as you can imagine, I can't deploy the application to the root path "/" in production because the server administrator will require obviously from me a specific and unique context path. 它使应用程序完美运行,但是,正如您可以想象的那样,我无法将应用程序部署到生产环境中的根路径“ /”,因为服务器管理员显然需要我提供特定且唯一的上下文路径。

I added below all steps and sources relevants to my question. 我在所有步骤和来源下方添加了与我的问题相关的内容。 I ordered from the less important to more important from my personal perspective (I do believe it may be something wrong with pom.xml but I may be wrong and I must change some spring configuration or Tomcat Server property). 从我个人的角度来看,我从不重要的顺序排列为重要的顺序(我确实相信pom.xml可能有问题,但是我可能有错,我必须更改一些spring配置或Tomcat Server属性)。

Take a note that, in browser I do see localhost:8080/calories-tracker no matter if I start/deploy "mvn clean install tomcat7:run-war" instead of "mvn tomcat7:deploy" in a previous started Tomcat server. 请注意,无论我是否在先前启动的Tomcat服务器中启动/部署“ mvn clean install tomcat7:run-war”而不是“ mvn tomcat7:deploy”,在浏览器中我都看到localhost:8080 / calories-tracker。

1 - In TomcatManager ( http://localhost:8080/manager/html/list ) 1-在TomcatManager中( http:// localhost:8080 / manager / html / list

I undeployed “/” 我取消部署“ /”

2 - Command Prompt of Windows 2-Windows的命令提示符

C:> mvn tomcat7:deploy

3 - Profile("development") 3-个人资料(“开发”)

@Configuration

@Profile("development")

@EnableTransactionManagement

public class DevelopmentConfiguration {



    @Bean(name = "datasource")

    public DriverManagerDataSource dataSource() {



    @Bean(name = "entityManagerFactory")

    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DriverManagerDataSource dataSource) {

4 - catalina.properties 4-catalina.properties

spring.profiles.active=development

5 - settings.xml 5-settings.xml

  <servers>

       <server>

              <id>tomcat8</id>

              <username>admin</username>

              <password>admin</password>

       </server>

  </servers>

6 - WebAppInitializer 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 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 8- Pom.xml

<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>

***Added few minutes after created the question The original project can be downlowed from https://github.com/jhades/spring-mvc-angularjs-sample-app . ***在创建问题后添加了几分钟。可以从https://github.com/jhades/spring-mvc-angularjs-sample-app下拉原始项目。 I just made the changes wrote above with Tomcat and Pom. 我刚刚对上面的Tomcat和Pom进行了更改。

you need to add $location to your controllers. 您需要向控制器添加$ 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: []
        };

then you store the context path in a scope variable and you can use it at the specified controller context. 然后将上下文路径存储在作用域变量中,然后可以在指定的控制器上下文中使用它。 maybe it's not the neatest way, but it works! 也许这不是最整洁的方法,但是它有效!

edit: first you need to change in login page the following tag for require 编辑:首先,您需要在登录页面中更改以下标记,以要求

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

then, if you like to see it in action 然后,如果您希望看到它的实际效果

<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">

but this will take some milliseconds to load which means that you will see for an instance the page without any css, till angular loads. 但这需要几毫秒的加载时间,这意味着您将看到一个实例,该页面没有任何CSS,直到有角度的加载为止。

you can see the difference you change the links to be of relative path. 您会看到将链接更改为相对路径的区别。

<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">

you can start by changing the links first and the POST/GET endpoints and then decide what to do with the styling links. 您可以先更改链接和POST / GET端点,然后再决定如何处理样式链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM