我正在使用Spring Web Services将服务公开为Web服务.在我的spring配置xml文件中,我有一个bean,它是DefaultWsdl11Definition的一个实例.需要设置的属性之一是locationUri.这需要是一个完全合格的Uri,但是当应用程序从dev升级到uat和生产时,我不想更改此值.Spring知道Web应用程序上下文根是什么,所以我可以在配置文件中指定一个变量来访问它吗?
就像是:
<bean id="myWebServices"
class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schemaCollection">
<bean
class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<property name="xsds" ref="xsdList"/>
<property name="inline" value="true" />
</bean>
</property>
<property name="portTypeName" value="myWebServices" />
<property name="locationUri" value="${webContextRoot}/webServices" />
</bean>
Run Code Online (Sandbox Code Playgroud) 我将我的Web应用程序部署到具有应用程序上下文的tomcat.例如,我的URL看起来像这样.
http://localhost:8080/myapp
Run Code Online (Sandbox Code Playgroud)
myapp - 这里是应用程序上下文.
现在在Angular服务中如果我想调用webservice说getusers.我的网址应该是这个/myapp/getusers.但我想避免硬编码应用程序上下文,因为它可能会从一个部署更改为另一个部署.我设法从中找出了contextpath,$window.location.pathname但它看起来非常愚蠢.有没有更好的办法?
仅供参考我使用Spring MVC来提供宁静的服务.
目前在JBOSS中部署了一场战争.如果我想在Jboss中找出WAR的上下文路径,我应该在哪里查看?在server.xml?
我知道在默认的Tomcat 8配置中,我可以将文件foo.war文件放入webapps/目录中,Tomcat将使用上下文路径自动部署我的Web应用程序/foo/.
如果我想要上下文路径,我会使用什么WAR文件名/foo/bar?
我正在使用版本2.4,Servlet我需要ContextPath通过init()在服务器启动时调用的方法,所以我没有任何可以调用的Request对象,getContextPath()因为Servlet版本我没有getContextPath()方法ServletContext.
有办法以ContextPath()某种方式得到这个吗?
升级到 Spring Boot 2.4 后,我的 Web 应用程序不再启动。它抛出以下错误:
Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码来更改上下文路径,我的研究指出这是“罪魁祸首”(更改上下文路径):
@Bean
public ServletWebServerFactory servletContainer()
{
String tomcatPort = environment.getProperty("tomcatPort");
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.setPort(tomcatPort != null ? Integer.parseInt(tomcatPort) : 8080);
tomcat.setContextPath("/Carbon");
tomcat.setBaseDirectory(new File(System.getenv("MDHIS3_HOME")));
setTomcatProtocol(tomcat);
return tomcat;
}
Run Code Online (Sandbox Code Playgroud)
我有以下方法,我可以看到它可以用来传递 defaultServletName 但我不知道我应该传递什么值:
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
{
configurer.enable();
}
Run Code Online (Sandbox Code Playgroud)
这在 Spring Boot 2.3.4 上运行良好。我在那里传递什么值?是主控制器的名字吗?
我在配置Tomcat项目时遇到了一些问题.简而言之,我正在开发一个动态网页项目,但似乎对我运行应用程序的位置存在一些困惑.
运行以下代码
File f = new File("");
System.err.println(f.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud)
产生输出C:/Eclipse恰好是我运行Eclipse的地方.通常情况下,我希望这是输出目录,但这次并非如此.
我的eclipse项目配置为将myProject/WebContent/WEB-INF/classes作为输出文件夹
如何配置到所需的目录?现在我需要使用绝对路径,这对于项目的所有成员都不起作用.
我通过将上下文路径设置为 /myservice 来运行我的 springboot 应用程序。这会导致附加在 URL- http://localhost:8080/myservice/actuator/ 上公开的所有执行器端点,而我只需要 http://localhost:8080/actuator/。有没有办法告诉 springboot 忽略附加上下文路径到执行器端点(通过 DispatcherServlet 或 CXFServlet 或任何东西)请帮忙。
我正在使用以下内容在我们的应用程序中获取帮助文档.我的问题是,在<h:graphicImage>正确评估上下文路径时,将其评估为h:outputLink空.我一直在使用这两种尝试$,并#在h:outputLink因为我知道他们有不同的考核时间.
两个EL表达式的评估方式有何不同?
<h:outputLink value="${pageContext.servletContext.contextPath}/services/help.pdf">
<h:graphicImage
url="${pageContext.servletContext.contextPath}/images/help.png"
alt="Online Help"/>
</h:outputLink>
Run Code Online (Sandbox Code Playgroud) 在我的Spring Boot(2.0)应用程序中,我在我的application.properties文件中设置了上下文路径,如下所示
server.servlet.context-path=/myApp
Run Code Online (Sandbox Code Playgroud)
另外,我有以下安全配置类扩展 WebSecurityConfigurerAdapter
@Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.GET,"/uifiles/dist/css/**").permitAll()
.antMatchers(HttpMethod.GET,"/uifiles/plugins/icheck-bootstrap/**").permitAll()
.antMatchers(HttpMethod.GET,"/uifiles/plugins/fontawesome-free/css/**").permitAll()
.antMatchers(HttpMethod.GET,"/css/**").permitAll()
.antMatchers(HttpMethod.GET, "/uifiles/**").permitAll()
.antMatchers(HttpMethod.GET, "/error/**").permitAll()
.antMatchers(HttpMethod.GET,"/files/**").permitAll()
.antMatchers(HttpMethod.GET,"/files/fonts/**").permitAll()
.antMatchers(HttpMethod.GET,"/files/images/**").permitAll()
.and()
.authorizeRequests().antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.successForwardUrl("/home")
.defaultSuccessUrl("/home")
.permitAll()
.and()
.logout()
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login")
.and()
.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint());
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序(来自Spring Tool Suit)并通过 url 访问应用程序时
它工作正常并打开登录页面
但是,当我进入
它将我重定向到 http://localhost:8080/login (这给出了一个 404 页面)
我想要 http://localhost:8080/myApp/ & http://localhost:8080/myApp/login 打开登录页面
登录页面位于项目文件夹的根目录中。另外,spring.mvc.view.suffix=.jsp我的 application.properties …
contextpath ×10
java ×5
spring-boot ×3
tomcat ×3
servlets ×2
angularjs ×1
eclipse ×1
el ×1
enterprise ×1
jboss ×1
jsf ×1
spring ×1
spring-mvc ×1
spring-ws ×1
tomcat8 ×1
tomcat9 ×1