跳至主要内容

博文

目前显示的是标签为“j2ee”的博文

Annotations in JBoss Deployment

在我们书写EJB代码时,为了简化配置,我们使用了注解而不是xml配置文件。那么,JBoss(或者说Wildfly)是如何利用这些注解,在合适的时候调用了我们的代码呢?换句话说,jboss从启动到输出像这样的jndi设置信息的部署过程究竟发生了什么?今天我们就通过分析其源代码简单探讨一下这个问题。 从annotations讲起 在开发过程中, 我们也时常会在应用代码中会看到这些看上去比较奇怪的@开头的东西,例如@Override, @Deprecated。他们的作用到底是什么?又是如何实现的呢?我们稍稍介绍以一跟我们今天内容相关的背景。 注解,根据其寿命长短,可以分为三类: Source:只存在于源代码中,在编译后便被丢弃。所以说他的作用范围便是编译时。 Class:在class文件中,但不在VM中。貌似没有什么卵用 Runtime:一直存活到VM中,即可以通过反射获得注释信息(用大白话说就是,当你程序跑起来之后,还可以获取注解的内容)。 所以,联想到我们在使用EJB的过程:先写好源代码,再编译,再打包,再交给jboss部署,jboss再调用我们的代码。我们可以明白,诸如@Stateless, @EJB这样的注解都是第三类注解。 JBoss部署 在上面讲的使用EJB的过程中,jboss的部署其实还是一个黑盒,所以当我们把我们的jar包部署到JBoss时究竟发生了什么? 让我们通过源代码(org/jboss/as/server/deployment/Phase.java)把部署过程理一理: /** * This phase creates the initial root structure. Depending on the * service for this phase will ensure that the * deployment unit's initial root structure is available and accessible. * Upon entry, this phase performs the following actions: * <ul> * <li>The primary deployment root is mounted...

Intellij Java EE Errors

Develop a web application using Tomcat Create project Choose a Java Enterprise project and select the Web application Framework, select your application server( If you don’t have one in idea, just click new and choose the root folder of your server to create one). Click Finish and you are ready to write your servlet Add JDBC support using DataSource and JNDI( taking mysql as an example) add driver to server-root-folder/lib/ add context.xml to context-root/META-INF/ (create one if not exist) with the following content: < Context > < Resource name = "jdbc/YourJNDIRegisteredName" auth = "Container" type = "javax.sql.DataSource" maxTotal = "50" maxIdle = "30" maxWaitMillis = "10000" logAbandoned = "true" username = "root" password = "" driverClassName = "com.mysql.jdbc.Driver" url = "jdbc:mysql://localhost:3306/YourMysqlDBName...