我正在考虑使用"轻量级"组件而不是完整的堆栈框架来开发新的Web应用程序.
这篇文章是我的主要灵感!
Jetty:Web服务器.我可能会使用embedabble版本进行开发,但可以选择将应用程序导出为.war并使用外部Jetty服务器进行生产环境.
Guice/Guice-Servlet:用于依赖注入和servlet映射+过滤器.
Jersey:用于路由+请求/响应json(de)序列化时的需要.
重要提示:我知道有些人会用这种栈中的泽西作为Web服务层而已,而会使用JavaScript框架(骨干,AngularJS等)使用这些服务,并完成大部分的表示逻辑在Javascript中.我还没有为这种客户端做好准备.我仍然喜欢使用JSP,并且能够将纯HTML发送到禁用了javascript的客户端.
所以,我的问题:
使用Jersey 管理表单的最佳方法是什么?使用Spring MVC(我在其他项目中使用),有一个"支持对象"的概念,其中提交的POST数据自动绑定到一个易于使用的支持对象.泽西有类似的东西吗?
我喜欢在一个特定的路由文件中定义所有路由,而不是像@Path注释那样在我看来更难管理.我很确定Jersey要求使用那些硬编码的JAX-RS的@Path注释并且不允许外部路由配置系统,这是正确的吗?您是否认为我可以用泽西岛集中所有路线?
我喜欢反向路由的概念(例如Play框架提供).而且,我认为泽西岛不能提供这种功能,这是正确的吗?
考虑到我以前的问题,也许Jersey不适合使用?你知道我可以用于堆栈中的路由部分的其他库吗?
有关这种轻量级Java Web堆栈的任何其他建议/提示吗?
更新:
我目前正在寻找UrlRewriteFilter作为路由部分.
我也在看ActiveWeb框架,它是一个"完整堆栈"框架,但看起来很轻,似乎也提供了一些我正在寻找的功能:集中式路由配置和反向路由.
我知道这可能不是最纯粹形式的依赖注入,但假设我必须使用:
@Inject
Injector injector;
Run Code Online (Sandbox Code Playgroud)
使用这个注入器,是否有可能获得所有给定的绑定实例:
我看到了Injector#findBindingsByType()方法,但我不确定它在这方面是否有帮助。
我正在使用Guice开发一个小型Web框架.我有一个Router对象,一旦初始化,就会公开一个getControllerClasses()方法.我必须使用Guice将所有动态返回的类循环到bind()它们.
我绑定路由器:
bind(IRouter.class).to(Router.class);
Run Code Online (Sandbox Code Playgroud)
但是,如何在Module中获取绑定的Router实例,这样我还可以绑定其getControllerClasses()方法返回的类?
我能够在模块中获取路由器实例的唯一方法是在第一个模块中绑定此实例,然后在setter上使用@Inject将其注入第二个模块:
第1单元
bind(IRouter.class).to(Router.class);
Module2 module2 = Module2();
requestInjection(module2);
install(module2);
Run Code Online (Sandbox Code Playgroud)
第2单元
@Inject
public void setRouter(IRouter router)
{
Set<Class<?>> controllerClasses = router.getControllerClasses();
for(Class<?> controllerClass : controllerClasses)
{
bind(controllerClass);
}
}
Run Code Online (Sandbox Code Playgroud)
调用该方法并初始化Router实例,但控制器类的绑定失败!在Guice生命周期的这一步,似乎module2 的binder实例是NULL.
如何绑定动态获取的类,这些类是否已由已绑定的对象返回?
我正在尝试生成一个包含main()的.jar ,它将启动Jetty.
我的问题是我希望Jetty加载的.war 包含在同一个.jar中.
我已经能够创建包含.war的.jar:
在POM.xml中:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<finalName>myApp</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.myApp.Server</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/executable-jar-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
executable-jar-assembly.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies-and-war</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>target/classes/</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>
myApp.war
</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
Run Code Online (Sandbox Code Playgroud)
在Jetty中设置战争的代码:
handler.setWar("myApp.war");
Run Code Online (Sandbox Code Playgroud)
......我也尝试过:
URL res = Server.class.getResource("myApp.war");
handler.setWar(res.toExternalForm());
Run Code Online (Sandbox Code Playgroud)
......和:
URL res = …Run Code Online (Sandbox Code Playgroud) 我知道用Java加载文件而不指定要使用的编码是依赖于平台的.但我的问题是关于包含在.java源文本文件本身:是否使用这些文件的编码仍然具有现实意义编译一次?
例如,如果我test.java在Windows上有一个Cp1252编码的文件并包含:
private String encodingTest = "Bœuf fûmé";
Run Code Online (Sandbox Code Playgroud)
如果我使用它编译它-encoding Cp1252,结果中的文本究竟发生了什么.class?编码仍然重要吗?或者编译时Java编码的编码是什么?
结果.class会取决于平台吗?如果我在Windows,Linux,Solaris上输出此文本,我可以得到不同的结果吗?服务器上的编码配置是否会以某种方式影响此文本的呈现?
我们是 Weblogic (12c) 的新手。我们尝试根据应用程序运行的环境(dev / staging /prod)选择如何将一些配置传递给应用程序。
我目前正在尝试使用部署计划。在WEB-INF/web.xml,我有:
<context-param>
<param-name>test</param-name>
<param-value>11111</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
plan.xml我在 Weblogic 中为我的应用程序使用了 a 。一些部分 :
<variable-definition>
<variable>
<name>test</name>
<value xsi:nil="false">22222</value>
<description>some description</description>
</variable>
</variable-definition>
Run Code Online (Sandbox Code Playgroud)
和
<module-descriptor external="false">
<root-element>web-app</root-element>
<uri>WEB-INF/web.xml</uri>
<variable-assignment>
<name>test</name>
<xpath>/web-app/context-param/[param-name="test"]/param-value</xpath>
<origin>planbased</origin>
<operation>replace</operation>
</variable-assignment>
</module-descriptor>
Run Code Online (Sandbox Code Playgroud)
这有效!
但我听说可以从管理控制台更改变量的值,是真的吗?
当我在控制台中(在Deployment Plan选项卡中或在Configuration选项卡中)浏览我的应用程序时,我没有看到任何可以用来更改test变量的字段......我是否遗漏了什么或必须在plan.xml文件本身?
我正在开发一个Spring Boot应用程序,我必须让它在我们的Weblogic 12c服务器中运行,作为一场战争.
我试图找到一种方法将默认的Spring活动配置文件(此处和此处的信息)传递给应用程序,而无需在计算机本身上设置环境变量.如果可能的话,我希望能够使用Weblogic管理控制台指定此配置文件.
我尝试使用" Environment / Servers / MyServer / Server Start / Arguments"选项,但我无法以这种方式使Spring加载指定的配置文件.我试过了,没有成功:
spring.profiles.active=dev
-Dspring.profiles.active='dev'
-Dspring.profiles.active=dev
-spring.profiles.active=dev
--spring.profiles.active=dev
Run Code Online (Sandbox Code Playgroud)
有没有想过是否可以spring.profiles.active使用Weblogic 传递给Spring?我需要传递" dev"," acc"或" prod".
更新:我会接受一个答案,解释.properties为应用程序配置使用不同文件的任何简单方法,具体取决于运行Sprint Boot应用程序的环境.这些.properties文件可以捆绑在应用程序本身中,也可以是外部的.但我需要至少尽可能触摸Weblogic运行的系统......没有环境变量,理想情况下也不会改变Weblogic文件!理想情况下,解决方案将涉及使用Weblogic管理控制台完成的某种操作,例如,将表示当前环境的参数传递给Spring Boot应用程序,以便使用正确的application.[ENVIRONMENT].properties文件.
更新2:允许每个环境拥有自己的application.properties文件的一种方法是使用部署计划.这可能是推荐的方法.我将补充一点作为答案,但我仍然倾向于采用一种更简单的方法......当我在Weblogic中部署参数时,我无法简单地将参数传递给应用程序!Environment / Servers / MyServer / Server Start / Arguments如果它不能用于那个目的,那么" 选择是什么?
更新3:相关主题.如果我理解正确," Environment / Servers …
假设我有这个HTML:
<html>
<head>
</head>
<body>
<form method="post">
<select name="books">
<option value="111">111</option>
<option value="222">222</option>
</select>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我将其加载到Jsoup中并返回结果:
Document doc = Jsoup.parse(html);
doc.outputSettings().indentAmount(4);
doc.outputSettings().charset("UTF-8");
doc.outputSettings().prettyPrint(true);
String result = doc.outerHtml();
Run Code Online (Sandbox Code Playgroud)
结果是:
<html>
<head>
</head>
<body>
<form method="post">
<select name="books"> <option value="111">111</option> <option value="222">222</option> </select>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
该<option>元素都是在同一行!
<option>在此示例中,如何让Jsoup格式化元素,使结果与输入相同?
假设我有一条由控制器处理的Express路线.控制器使用服务,服务使用存储库与数据源通信.
我想使用Supertest创建一个集成测试来测试该路由:
test -> my Express app -> controller -> service -> repository -> data source
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要模拟存储库/数据源,来运行测试!我想硬编码一些值,好像它们来自真实的数据源.我有什么选择?
在Java世界中,我将使用Spring或Guice的依赖注入,我会用这样的模拟版本替换存储库.在Typescript/Node.js世界中实现这种模拟的模式是什么?
我想使用普通的Javascript我可以使用Proxyquire它的全局覆盖需要功能,从测试本身模拟存储库.但我不确定这适用于Typescript.
那么使用Typescript和Node.js从测试文件中模拟"深层"组件(传递依赖)的推荐方法是什么?
java ×5
guice ×3
weblogic ×2
weblogic12c ×2
grails ×1
html-parsing ×1
jakarta-ee ×1
javac ×1
jersey ×1
jetty ×1
jsoup ×1
log4j ×1
logging ×1
maven ×1
node.js ×1
proxyquire ×1
spring ×1
spring-boot ×1
supertest ×1
typescript ×1