目前我正在将我的Java Web应用程序从JDBC切换到Hibernate,在我当前的JDBC实现中,我将应用程序初始化时的静态数据加载到静态变量中,所以每次我需要一些静态数据时都不必直接访问数据库,现在切换到hibernate我正在考虑摆脱这些静态变量,因为我已经研究过hibernate将数据保存在缓存中.
我对hibernate相当新,所以我不确定从我当前的方法切换到hibernate是否会提高性能.我将进一步研究hibernates缓存并运行一些性能测试,以查看哪种方法更好,但只是想对其他人对这两种方法的性能有何看法.
谢谢.
尝试运行以下代码以使用tomcat上下文文件获取javax.mail.Session对象时,我一直收到此错误.
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (javax.mail.Session) envCtx.lookup("mail/session");
Run Code Online (Sandbox Code Playgroud)
这是context.xml中的资源声明.
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"
mail.smtp.host="host"
mail.smtp.user="user"
mail.smtp.password="password"
mail.smtp.auth="false"/>
Run Code Online (Sandbox Code Playgroud)
我理解这可能是因为我在我的应用程序服务器库(tomcat)文件夹中的javax.mail.Session具有相同的库,并且在我的应用程序库文件夹中,我从我的应用程序库文件夹中删除了尽可能多的重复库文件(例如, mail.jar)我可以看到将javax.mail.Session作为库的一部分,现在我处于这样的程度,我仍然遇到此错误并且不确定其他库可能是此问题的根源,或者这是我不知道的其他问题吗?
人们建议我做些什么来找到这个问题的根源?
谢谢.
是否可以使用每个请求的client_credentials或密码授予类型生成多个有效的访问令牌?
使用上述授权类型生成令牌仅在当前请求到期时提供新令牌.
我可以使用密码授予类型生成刷新令牌,然后生成多个访问令牌,但这样做会使以前的任何访问令牌无效.
知道如何更改以允许每次请求生成访问令牌到/ oauth/token端点并确保任何以前的令牌都没有失效?
下面是我的oauth服务器的XML配置.
<!-- oauth2 config start-->
<sec:http pattern="/test/oauth/token" create-session="never"
authentication-manager-ref="authenticationManager" >
<sec:intercept-url pattern="/test/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<sec:anonymous enabled="false" />
<sec:http-basic entry-point-ref="clientAuthenticationEntryPoint"/>
<sec:custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
<sec:access-denied-handler ref="oauthAccessDeniedHandler" />
</sec:http>
<bean id="clientCredentialsTokenEndpointFilter"
class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider user-service-ref="clientDetailsUserService" />
</sec:authentication-manager>
<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<bean id="clientDetails" class="org.security.oauth2.ClientDetailsServiceImpl"></bean>
<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="springsec/client" />
<property name="typeName" value="Basic" />
</bean>
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler"/>
<oauth:authorization-server
client-details-service-ref="clientDetails" token-services-ref="tokenServices">
<oauth:authorization-code />
<oauth:implicit/>
<oauth:refresh-token/>
<oauth:client-credentials /> …Run Code Online (Sandbox Code Playgroud) I am trying to return one of my entities to a JSP page but getting the following error "failed to lazily initialize a collection of role". I have added the openEntityManagerInView filter(assuming it would allow the entity manager to stay open in the view?) but still getting this error.
My application is configured using java config no xml.
Below is my dispatcher servelet. You can see i have added the openEntityManagerInView filter.
Any ideas why this is? I have checked …
我正在尝试解析一些无效的xml,因为属性不在引号中,有没有办法解决这个问题?下面是一个简单的例子,以及java代码.
XML
<car id=1>
.
.
</car>
Run Code Online (Sandbox Code Playgroud)
Java的
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(page, handler); //page is an input stream where the xml is.
Run Code Online (Sandbox Code Playgroud)
谢谢.
我想要一些关于jdbc的并发问题的建议,我基本上需要更新一个值,然后使用更新然后选择检索该值,我假设通过关闭自动提交关闭没有其他事务可以访问此表,因此其他事务在提交之前,将无法执行更新和选择查询.
下面是一些示例代码.你认为这会有效吗?其他人有没有更好的解决方案来实现这个?
int newVal=-1;
con.setAutoCommit(false);
PreparedStatement statement = con.prepareStatement("UPDATE atable SET val=val+1 WHERE id=?");
statement.setInt(1, id);
int result = statement.executeUpdate();
if (result != 1) {
throw new SQLException("Nothing updated");
} else {
statement = con.prepareStatement("SELECT val FROM atable WHERE id=?");
statement.setInt(1, id);
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
newVal = resultSet.getInt("val");
}
}
statement.close();
con.commit();
con.setAutoCommit(true);
Run Code Online (Sandbox Code Playgroud)
谢谢.